Page 1 of 1

Iframe tags Regex

Posted: Mon Oct 26, 2009 11:05 am
by trogster
Hi, I'm trying to parse iframe tags from html.
I have this pattern so far:

Code: Select all

'#<iframe[^>]*>.*?</iframe>#i'
This works ok for something like:

Code: Select all

<iframe src='http://www.example.com' width='XXX' height='XXX'></iframe>
and
<iframe src='http://www.example.com' width='XXX' height='XXX'><a href="http://www.example.com">iframes not supported</a></iframe>
But I want to parse also iframe tags like this one:

Code: Select all

<iframe src='http://www.example.com' width='XXX' height='XXX' />
Does anyone knows how to parse that last iframe code (and the previous) in the same pattern?

Thanks.

Re: Iframe tags Regex

Posted: Mon Oct 26, 2009 11:37 am
by trogster
I think I solved it.

Code: Select all

'#<iframe[^>]*>.*?(</iframe>)?#i'
or

Code: Select all

'#(?:<iframe[^>]*)(?:(?:/>)|(?:>.*?</iframe>))#i'
Both seems to work fine.