Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Fabio, john.k.doe, CraigTeegarden, soon, jcwenger Jun 3 '13 at 2:31

This question was marked as an exact duplicate of an existing question.

1  
Looks like HTML to me ? – adeneo May 31 '13 at 21:56
    
It does not have the html start and end tags though – Manas Paldhe May 31 '13 at 21:56
1  
Does it have XML start tags then? It's still HTML. – adeneo May 31 '13 at 21:57
    
No. I just have the string in the above-mentioned format. – Manas Paldhe May 31 '13 at 21:57
    
@Prix: I dont think so. Since this does not have xml or html tags it is not getting accepted as html or xml. So I am unable to use those. – Manas Paldhe May 31 '13 at 22:04
up vote 0 down vote accepted

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'
?>
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.