0
A
回答
-2
可能:
if(str_replace("<a", "<a", $text)) {
echo "ok";
} else {
echo "not ok";
}
+0
您正在使用'str_replace'进行不必要的工作 - 用相同的字符串替换字符串。使用这种构造会降低代码的可读性。 – 2012-01-11 21:54:12
0
为了解析HTML,最好使用某种DOM解析器,这里更多的信息:PHP HTML DOM Parser,但如果你的目标只是要检查HTML标签的存在,preg_match
可以成为解决方案:
$text="<a href>the hero</a>";
var_dump(preg_match("/\<a.*\>(.*?)\<\/a\>/si", $text));
1
如果你只是想检查字符串使用strpos中是否存在“< a”。它比preg_ *快得多,它必须首先编译一个正则表达式。
<?php
$exists = (strpos($text , '<a') !== false);
?>
相关问题
- 1. 查找网址,而忽略HTML标签
- 2. 查找HTML文本和标签父
- 3. 查找HTML标签之间的文本
- 4. 在HTML文档中查找标签
- 5. 查找标签
- 6. 查找使用Textmate嵌套在php中的闭合html标签?
- 7. 查找带有各种html标签的字符串PHP
- 8. php正则表达式:查找html标签之间的内容
- 9. php - textarea- html标签
- 10. PHP和html标签
- 11. 查找标签页
- 12. 查找TODO标签
- 13. PHP:更换标签HTML
- 14. 如何preg_match php html标签?
- 15. PHP呼应HTML标签
- 16. PHP MySQL输入HTML标签
- 17. 使用PHP HTML标签内
- 18. Php包括和html标签
- 19. php json_decode删除html标签
- 20. php preg_replace html标签问题
- 21. PHP - 删除HTML标签
- 22. PHP nodevalue剥离html标签
- 23. PHP解析HTML标签
- 24. 用html替换php标签
- 25. PHP HTML注释/标签
- 26. PHP DOMDocument剥离HTML标签
- 27. 如何在非html文件中查找html标签?
- 28. 查找相关标签
- 29. 在wordpress中查找并替换html标头标签
- 30. XPath查询和HTML - 在锚标签中查找特定的HREF
你想知道你的字符串中是否有标签?删除标签?或知道哪些标签在那里?根据你的答案,真正的答案会有所不同 – 2012-01-11 21:43:37
有点点:http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html – Wrikken 2012-01-11 21:45:37
我想检查“ user1017808 2012-01-11 21:50:40