Iframe tags Regex

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
trogster
Forum Newbie
Posts: 3
Joined: Sun Oct 05, 2008 10:05 pm

Iframe tags Regex

Post 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.
trogster
Forum Newbie
Posts: 3
Joined: Sun Oct 05, 2008 10:05 pm

Re: Iframe tags Regex

Post 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.
Post Reply