-3

我有一个格式为:

 <!--Vendor: A, Format: IFrame, IO: -->
 <iframe src="xyz.com "scrolling="no" width="180" height="150" frameborder="0" marginheight="0" marginwidth="0" title="Advertisement"></iframe>

这对我来说看起来像 xml 字符串。但是 $xml=new SimpleXMLElement($string) 给出格式错误。我尝试添加最后但没有用。我需要从中提取各种参数。最好的方法是什么?

4

1 回答 1

0

它是 HTML,可以解析为 HTML,试试这个:

<?php
    $html = '<!--Vendor: A, Format: IFrame, IO: --><iframe src="xyz.com "scrolling="no" width="180" height="150" frameborder="0" marginheight="0" marginwidth="0" title="Advertisement"></iframe>';

    $doc = new DOMDocument();
    $doc->loadHTML($html);
    $iframe = $doc->getElementsByTagName('iframe');
    $iframe_scrolling = $iframe->item(0)->getAttribute('scrolling');

    echo $iframe_scrolling; // outputs 'no'
?>
于 2013-05-31T22:04:00.670 回答