I tried to get the src of an iframe inside of an html using this
preg_match('/src=\'([^\']+)\'/', $fresult, $match);
but this code sometimes fails.
some sugest that I use an DomDocument But I can't found a reg exp sample
$doc = new DOMDocument();
$doc->loadHTML($html);
foreach ($tags as $tag) {
echo $tag->nodeValue;
}
How do I get the src value of frame?
sample
<iframe src='test.com' />
i should have test.com
also how do I do the preg_match_all equivalent of DomDocument?
like this
<html>
<label class="su">test1</label>
<label class="su">test2</label>
<label class="su">test3</label>
</html>
which is I should have a array result for test1, test2 and test3
I am new to this dom php thing. so please don't be harsh. thanks
First of all, welcome to Stack Overflow! Please do not use regular expressions on DOM documents (see here why). Instead, please stick to PHP DomDocument.
That said, you may get an iframe tag and src like so:
$doc = new DOMDocument();
$doc->loadHTML(...);
$frame= $doc->getElementsByTagName('iframe')->item(0);
$src = $frame->getAttribute('src');
Concerning your second question, you might want to have a look at DOMXPath:
$doc = new DOMDocument();
$doc->loadHTMLFile(...);
$xp = new DOMXPath($dom);
$labels = $xp->query('//label[@class="su"]');