2012-11-24 42 views
1

我想將下面的腳本作爲變量使用文本區域表單存儲,但是當我執行並回顯變量時,瀏覽器會解釋代碼。我不想要這個,我只是想將腳本「按原樣」存儲在變量中,以便我可以使用該變量進行進一步操作。任何想法如何我可以使用PHP中的文本區域形式來完成這一點?如何在腳本格式中使用php作爲字符串存儲變量

<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;" /> 

順便說一句,下面是我想要當用戶把上面的腳本在文本區域的確切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;" />"; 

任何幫助,非常感謝。感謝

+0

行情。行情。行情。 –

回答

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); 
?> 
+0

刪除了所有語法錯誤。現在它的工作正常 –

+0

謝謝Pankaj,它的工作原理! – anagnam

+0

@anagnam這很好我也改變了你的$ str變量,這個變量被雙引號括入單引號 –

0

如果需要輸出HTML你的價值,你需要&lt;&gt;更換你<>。最好的是使用htmlspecialchars()功能。

此外,您被告知正確您的字符串中有未轉義的引號(用\"替換引號內)。

相關問題