Display only Iframe value

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
shafiq2626
Forum Commoner
Posts: 88
Joined: Wed Mar 04, 2009 1:54 am
Location: Lahore
Contact:

Display only Iframe value

Post by shafiq2626 »

Hi
I have some description and Iframe value in my database fields . I want to display only Iframe value. Like this
<p>Description:</p>
<p>In this action packed multi level game, you've to help A.L.I.A.S to battle his way through the army base and blast all the enemies and obstacles with his high fire rate gun. Each kill restores a bit of health (power-ups help for that, too). At the end of the game, your score will be multiplied by the number corresponding to the chosen difficulty level...Good
[button link="http://graggles.com/help/" type="icon" icon="notice" newwindow="yes"] Game is not working? (Click here) [/button]
<iframe src="http://www.freeonlinegames.com/embed.php?g_id=924" width="550" height="350" scrolling="no" allowTransparency="true" frameborder="0"></iframe>


I want to take only
<iframe src="http://www.freeonlinegames.com/embed.php?g_id=924" width="550" height="350" scrolling="no" allowTransparency="true" frameborder="0"></iframe>
from above value.
How this can b possible in php.
thanks
genix2011
Forum Commoner
Posts: 74
Joined: Tue Aug 02, 2011 4:00 pm

Re: Display only Iframe value

Post by genix2011 »

Hi,

you can use regular expressions in PHP with preg_match, this would look like that:

Code: Select all

$searchin = <<<EOF
<p>Description:</p>
<p>In this action packed multi level game, you've to help A.L.I.A.S to battle his way through the army base and blast all the enemies and obstacles with his high fire rate gun. Each kill restores a bit of health (power-ups help for that, too). At the end of the game, your score will be multiplied by the number corresponding to the chosen difficulty level...Good
[button link="http://graggles.com/help/" type="icon" icon="notice" newwindow="yes"] Game is not working? (Click here) [/button]
<iframe src="http://www.freeonlinegames.com/embed.php?g_id=924" width="550" height="350" scrolling="no" allowTransparency="true" frameborder="0"></iframe>
EOF;

preg_match("/\<iframe src=\"(.*)\" width.*\>\<\/iframe\>/", $searchin, $matches);
$matches[0] will return the whole <iframe>, and $matches[1] will return only the src part.

Greets.
Post Reply