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