删除特殊字符,如<;p><;李>;


To remove special characters like <p>, <li>

我想在客户端显示内容。问题是我得到的输出是这样的-

<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="<p>测试<p>";

$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']);
}

如果它们是标记,则可以使用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>

要清除文本中的所有html标记,请使用strip_tags()函数。你可以在文档中看到用法。如果您需要清除除少数需要的标记外的所有标记,只需输入"allowable_tags"param即可。http://www.nusphere.com/kb/phpmanual/function.strip-tags.htm

使用PHP函数strip_tags删除标签

<?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>');
?>