Jump to content

Get Text Between Tags


daneilair

Recommended Posts

Okay I'm trying to make a blog-type-thing where when the user wants to use a video it will take the info given and turn it into code. The code saying you want to use a video is this

[video title="video title" url="C:\...\video.flv" height="260" width="320"][/video]

But I cant figure out how to use PHP to get the title, url, height, and width and then set each as a variable. I tried using "preg_match()" but I cant get it to work. If you could give me a hand with this that would be awesome.

 

Thanks,

Daniel

Link to comment
https://forums.phpfreaks.com/topic/188621-get-text-between-tags/
Share on other sites

$string = '[video title="video title" url="C:\...\video.flv" height="260" width="320"][/video]';
preg_match('/(.*title=")(.*)(" url=")(.*)(" height=")(\d*)(" width=")(\d*)(".*)/', $string, $matches);
print_r($matches);
$title = $matches[2];
$filename = $matches[4];
$height = $matches[6];
$width = $matches[8];

 

How the regexp is working:

(.*title=") - Find any number of characters up to ' title=" ' (whats before title)

(.*) - Find any number of characters (title)

(" url=") - Up to ' " url=" ' (what's between title and filename)

(.*) - Find any number of characters (filename)

(" height=") - Up to ' " height=" ' (what's between filename and height)

(\d*) - Find any number of digits (height)

(" width=") - Up to ' " width=" ' (what's between height and width)

(\d*) - Find any numberof digits (width)

(".*) - Up to ' " ' and then find any number of characters remaining (.*)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.