Page 1 of 1

Match for src-part of frame-tag

Posted: Fri Aug 19, 2005 6:58 pm
by tores
Hi

How can I extract all sources of each frame-tag. E.g if I had the following two frame tags in some html.

Code: Select all

<frame name="right" src="right.html" scrolling="no">
<frame name="left" src="left.html" scrolling="no">
I want the regexp to return right.html and left.html...

I guess something like

Code: Select all

preg_match('[magic regexp]', $html, $matches);
should do the trick

Posted: Fri Aug 19, 2005 8:27 pm
by McGruff
If you can rely on the html being written exactly as above, use look ahead/behind:

Code: Select all

/(?<=<frame\s+name="right"\s+src=")[^"]+(?=")/i
It will break if the name/src order changes.

Posted: Sat Aug 20, 2005 11:36 am
by Chris Corbyn
... whereas this one won't break so long as they are frame's ;)

Code: Select all

function getFrameSrc($code)
{

    preg_match_all('/<frame [^>]*?\bsrc="([^"]+)"[^>]*>/is', $code, $matches);
    return $matches[1]; //Uni-dimensional array of src's

}