我有一个字符串,格式为:
<!--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)给出格式错误。我最后试着加了,但没有用。我需要从中提取各种参数。最好的方法是什么?
这是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'
?>