-3

I have a string that is of the format:

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

This looks xml like string to me. However $xml=new SimpleXMLElement($string) gives format error. I tried adding in end but no use. I need to extract various parameters out of this. What is the best way to go about it?

Prix
  • 19,417
  • 15
  • 73
  • 132
Manas Paldhe
  • 766
  • 1
  • 10
  • 32

1 Answers1

0

It's HTML and can be parsed as HTML, try this :

<?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'
?>
adeneo
  • 312,895
  • 29
  • 395
  • 388