我想在客户端显示内容。问题是我得到这样的输出 -
<p> Aliette is a systemic fungicide effective against Oomcytes fungi like downy mildew
diseases of grapes and damping off and Azhukal diseases of cardamom.</p> <span> Despite
its extensive use since 1978, there is no report of resistance development in fungus.
True systemic action makes application of Aliette as the best prophylactic solution for
downy mildew control in grape.</span>
现在我想删除那些特殊字符,例如<p>
,</p>
,<span>
,</span>
存储在数据库中的值是description =“&lt; p&gt; test&lt; p&gt;”;
$sel_pro = "select * from bayer_product where product_group like '%".$_REQUEST['searchfield']."%'";
$res_pro = mysql_query($sel_pro);
$num_pro = mysql_num_rows($res_pro);
while($row_pro = mysql_fetch_assoc($res_pro))
{
echo $desc = strip_tags($row_pro['description']);
}
答案 0 :(得分:7)
如果它们是标签,那么您可以使用strip_tags()
.
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
// Allow <p> and <a>
echo strip_tags($text, '<p><a>');
输出将是
Test paragraph. Other text //strip all tags
<p>Test paragraph.</p> <a href="#fragment">Other text</a> //strip all tags except <p> & <a>
答案 1 :(得分:2)
要清除文本中的所有html标记,请使用strip_tags()
函数。您可以在文档中看到的用法。如果您需要清除所有标签,除了您需要的少数标签 - 只需输入&#34; allowable_tags&#34; PARAM。
http://www.nusphere.com/kb/phpmanual/function.strip-tags.htm
答案 2 :(得分:1)
使用PHP函数strip_tags删除标记 p>
<?php
$text = '<p> Aliette is a systemic fungicide effective against Oomcytes fungi like downy mildew
diseases of grapes and damping off and Azhukal diseases of cardamom.</p> <span> Despite
its extensive use since 1978, there is no report of resistance development in fungus.
True systemic action makes application of Aliette as the best prophylactic solution for
downy mildew control in grape.</span>';
echo strip_tags($text);
echo "\n";
// Autorise <p> et <a>
echo strip_tags($text, '<p><span>');
?>