1

我想使用文本区域表单将此脚本存储为下面的变量,但是当我这样做并回显变量时,浏览器会解释代码。我不想要这个,我只想将脚本“按原样”存储在一个变量中,这样我就可以使用该变量进行进一步的操作。任何想法如何使用 php 中的文本区域表单来完成此操作?

<a href="https://rads.stackoverflow.com/amzn/click/com/B008EYEYBA" rel="nofollow noreferrer"><img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&ASIN=B008EYEYBA&Format=_SL110_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=mytwitterpage-20" ></a><img src="http://www.assoc-amazon.com/e/ir?t=mytwitterpage-20&l=as2&o=1&a=B008EYEYBA" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />

顺便说一句,当用户将上面的脚本放在文本区域中时,下面是我想要的确切 php 变量。

$str = "<a href="https://rads.stackoverflow.com/amzn/click/com/B008EYEYBA" rel="nofollow noreferrer"><img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&ASIN=B008EYEYBA&Format=_SL110_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=mytwitterpage-20" ></a><img src="http://www.assoc-amazon.com/e/ir?t=mytwitterpage-20&l=as2&o=1&a=B008EYEYBA" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />";

任何帮助是极大的赞赏。谢谢

4

2 回答 2

3

像这样使用

<?php
$str = '<a href="http://rads.stackoverflow.com/amzn/click/B008EYEYBA"><img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&ASIN=B008EYEYBA&Format=_SL110_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=mytwitterpage-20" ></a><img src="http://www.assoc-amazon.com/e/ir?t=mytwitterpage-20&l=as2&o=1&a=B008EYEYBA" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />' ;
echo htmlentities($str);
?>
于 2012-11-24T05:26:37.307 回答
0

如果您需要以 HTML 格式输出您的值,则需要将您的<and>替换为&lt;and &gt;。最好是为此使用htmlspecialchars()功能。

此外,您被正确告知您的字符串中包含未转义的引号(将引号内的引号替换为\")。

于 2012-11-24T05:26:28.787 回答