0
我有类似:PHP正则表达式:在span.class删除括号内的文字
<span class="product-title">title (description)</span>
,我想用PHP括号和所有span.product-title
的内容删除,是这样的:
<span class="product-title">title</span>
我成功删除了文本和括号(/\s\([^)]+\)/
),但我只想匹配span.product-title
中的内容。
我该怎么做?
在此先感谢。 :)
不要在html上使用正则表达式。使用DOM隔离该跨度,提取其文本内容,然后处理JUST该文本字符串 –
要扩展@ MarcB的评论,签出['DOMDocument'](http://php.net/manual/en/class.domdocument。 PHP)和['XPath'](http://us2.php.net/manual/en/simplexmlelement.xpath.php)。用于检索特定类的XPath查询将是// // span [@ class =“product-title”]'。 – Sam