問題描述
DOMDocument:如何解析類似 bbcode 的標籤? (DOMDocument : how to parse a bbcode like tag?)
我對 DOMDocument 使用的查詢有疑問。我將在字符串中使用“bbcode like”標籤並找到屬性 data_id。
我使用下面的 thp 代碼,但我總是收到這些警告:警告:DOMXPath::query(): Invalid expression
p>我希望你使用的“bbcode like”代碼:
[sondage data_id=1]
PHP 代碼
$doc = new DOMDocument();
$doc‑>loadHTML($row‑>text);
$selector = new DOMXPath($doc);
$result = $selector‑>query('//[sondage');
foreach($result as $node) {
echo $node‑>getAttribute('data_id');
}
感謝您的幫助
參考解法
(by Raphael)