【问题标题】:How to display special html characters in title tag如何在标题标签中显示特殊的 html 字符
【发布时间】:2015-02-10 15:57:32
【问题描述】:

我有一个链接到 php 页面的锚标记,我想在 url 参数中使用特殊字符title

我要传入url的字符串:

Which is better approach to use href="#" or href="javascript:void(0)"

我的锚标记 href 将如下所示:

mypage.php?title=Which is better approach to use href="#" or href="javascript:void(0)"

在我的 php 页面上,当我回显 $_GET["title"];我只得到部分字符串:

Which is better approach to use href="

如何显示我在锚标签中使用的确切标题

【问题讨论】:

  • 您能否尝试提供更多详细信息并尽可能多地解释,我不确定您要问的是什么......
  • 我同意@ForceBru。你应该更关心这个问题。
  • 如果我没看错,你忘了在 href 属性的末尾加上 ",这意味着你的 html 已损坏。
  • 我想在回显标题值时显示标题的确切值
  • 如何在标题标签中显示special html characters。好吧,标题标签是<title>This</title>,它位于页面顶部,但您没有任何东西可以显示您尝试将任何文本放入title 您应该编辑您的问题,因为问题标题非常具有误导性,您也不要显示任何special html characters 的迹象。

标签: php html url


【解决方案1】:

您必须先对字符串进行编码,然后再将其发送到标题变量。

示例:

$title = 'Which is better approach to use href="#" or href="javascript:void(0)"'
echo '<a href="mypage.php?title='. urlencode($title) . '">';

// and to get the title
echo urldecode($_GET["title"]);

【讨论】:

    【解决方案2】:

    使用urlencode() 输出您的链接并使用urldecode() 在其他页面中回显它们:

    首页:

    <?php
    $link = urlencode('Which is better approach to use href="#" or href="javascript:void(0)"');
    
    echo '<a href="mypage.php?title=' . $link . '">a link</a>';
    ?>
    

    你会在 mypage.php 上做:

    <?php
    echo urldecode( $_GET['title'] );
    ?>
    

    【讨论】:

      【解决方案3】:

      PHP $_GET['title'] 是 get 数组的变量“title”,实际上是 ? 之后的变量。在一个网址中。

      <a href="index.php?title=TheTitle">test</a>
      

      这将显示 TheTitle

      但您可能希望 url 转义标题。

      <a href="mypage.php?title=<?php echo urlencode('Which is better approach to use href="#"') ?>">Link</a>
      

      【讨论】:

      • 不知道 - 那就不要回答:)
      • 我指出了正确的方向。我知道这是可能的。顺便说一句,它是 urlencode($string)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-19
      • 2011-10-04
      • 2012-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多