如何在标题标签中显示特殊的html字符


How to display special html characters in title tag

我有一个链接到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="

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

在将字符串发送到标题变量之前,必须对其进行编码。

示例

$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"]);

使用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'] );
?>

PHP$_GET['title']是GET数组的变量"title",实际上是?在url中。

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

这将显示标题

但你可能会想通过url逃离标题。

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