我正在尝试创建一个将在我的网站上显示的文本框。当显示时,我想在文本框中显示一些数据。这是我所拥有的
echo "<input type=\"text\" size=\"100\" value=\"<a href=\"$url\"></a>\">";在文本框中显示的所有内容都是<a href=,然后在文本框的末尾,我看到了">
我知道有些东西一定是语法错误的,只是不确定是什么。
发布于 2011-06-09 04:33:11
您必须对<、"和>字符进行编码-它们不能以这种方式嵌入。使用:
echo '<input type="text" size="100" value="'.htmlspecialchars('<a href="'.$url.'"></a>').'">';你也可以使用urlencode()函数-看看哪个更适合你。
另一个提示-当字符串包含类似HTML的内容时,请使用单引号。这将省去你到处添加\"的麻烦。
发布于 2011-06-09 04:34:07
php_code ?>
<input type="text" size="100" value="<a href="e;<?=$url;?>"e;></a>\">
<?php
php_code也许这对你有用
发布于 2011-06-09 04:36:40
想象一下html是什么样子的:
<input type="text" size="100" value="<a href="$url"></a>">
^
|
This is where the value attribute ends!htmlspecialchars应该可以解决这个问题。
https://stackoverflow.com/questions/6284874
复制相似问题