如何在标题标签中显示特殊 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 页面上,当我 echo $_GET["title"];我只得到部分字符串:
Which is better approach to use href="
如何显示我在锚标签中使用的确切标题
PHP$_GET['title']是get数组的变量"title",实际上是?后面的变量在 url.
<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>
您必须在将字符串发送到标题变量之前对其进行编码。
示例:
$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()
to output your links and 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 页面的锚标记,我想在 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 页面上,当我 echo $_GET["title"];我只得到部分字符串:
Which is better approach to use href="
如何显示我在锚标签中使用的确切标题
PHP$_GET['title']是get数组的变量"title",实际上是?后面的变量在 url.
<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>
您必须在将字符串发送到标题变量之前对其进行编码。
示例:
$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()
to output your links and 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'] );
?>