2010-12-10 42 views
0

,大家好,我目前使用这样的:想要去除特定字符

$meta = htmlspecialchars($m); 

这一个是剥离所有HTML chars..But我想只是删除“<”和“>”

我该怎么做?

感谢

+0

你想用它们的HTML替换它们,或者直接删除它们吗? – AlastairG 2010-12-10 15:16:34

回答

4

从字符串中删除所有<>字符,请使用

$meta = str_replace(array('<','>'), '', $m); 
+0

没有必要提供一个空白数组作为第二个参数,只需'就够了。 – 2010-12-10 15:17:54

+0

哈,我在仔细检查,当你评论 – Gareth 2010-12-10 15:19:48

+0

解析错误:语法错误,意想不到的'<'在49行/home/searchru/public_html/web-search.phtml – 5416339 2010-12-10 15:33:10

1

这将 ''(无)更换<>字符。

$cleantext = str_replace(array('<', '>'), '', $text); 

或者将它们替换为编码字符。

$cleantext = str_replace(array('<', '>'), array('&lt;', '&gt;'), $text); 
+0

解析错误:语法错误,在第49行的/home/searchru/public_html/web-search.phtml中出现意外的'<' – 5416339 2010-12-10 15:32:14

+0

您是否在前面的行中检查过您的代码?你可能有一个未封闭的'''。 – 2010-12-10 15:35:03

+0

是的,我做了..但没有发现! – 5416339 2010-12-10 15:39:40