0
我有一个包含一段文本(带有html标签)的php变量($string
)。我想要做的只是过滤一个标签:<object></object>
。使用php过滤一个html标签
有没有发现迄今为止的任何解决方案...
我有一个包含一段文本(带有html标签)的php变量($string
)。我想要做的只是过滤一个标签:<object></object>
。使用php过滤一个html标签
有没有发现迄今为止的任何解决方案...
可以使用DOMDocument::loadhtml
来从$string
的HTML,你可以使用它像这样:
<?php
$DOM = new DOMDocument;
//Parsing the string into html
@$DOM->loadHTML($string);
//Getting all the elements with the <object> tag
$objects = $DOM->getElementsByTagName("object");
?>
阅读更多关于DOMDocument
在here类。
你到目前为止尝试过什么?请发布您的代码,输入和所需的输出。 – 2014-10-05 10:07:58
这是通过过滤器学习[PHP RegEx函数](http://php.net/manual/en/ref.pcre.php) – kums 2014-10-05 10:28:37
的好时机,是否意味着您只允许该标记或删除只有那个标签? – Jonathan 2014-10-05 11:23:33