Jump to content

Help with a regex expression


bms231

Recommended Posts

ok so i don't know php but a friend told me this is the place to ask.... so this is what i am doing....

 

i need to grab the string after /video/ and before .htm

 

http://videos.streetfire.net/video/bceb6963-b1b7-4ced-9075-423ce6135921.htm

 

so i can make a string like this

 

        http://videos.streetfire.net/vidiac.swf?video=bceb6963-b1b7-4ced-9075-423ce6135921

 

 

 

here is where i am trying to do it:

 

if (preg_match('/video/(.*)$/', $this->_mediaInfo['url'], $match))

 

 

^^^  i know this is not right.  what should it be?  i need to use preg_match.

 

Link to comment
Share on other sites

$pattern = "#\/video\/(.*)\.htm#";

 

That should work... I'll test it in a second....

 

Edit: just tested it and

$url = "http://videos.streetfire.net/video/bceb6963-b1b7-4ced-9075-423ce6135921.htm";
$pattern = "#\/video\/(.*)\.htm#";
if(preg_match($pattern, $url, $match)) {
echo $match[1];
}

returns "bceb6963-b1b7-4ced-9075-423ce6135921"

Link to comment
Share on other sites

o darn one thing i forgot to add is it has to be able to detect the '-' as well

 

i am doing detection on multiple strings and streetfire is the only url w/ - in it so i figure that is what i will use to determine if it is streetfire or not.

 

 

 

 

this would be a wish, i think i may be able to use ur solution already unless u wanna try and verify the -

Link to comment
Share on other sites

$pattern = "#\/video\/(.*)\.htm#";

 

That should work... I'll test it in a second....

 

Edit: just tested it and

$url = "http://videos.streetfire.net/video/bceb6963-b1b7-4ced-9075-423ce6135921.htm";
$pattern = "#\/video\/(.*)\.htm#";
if(preg_match($pattern, $url, $match)) {
echo $match[1];
}

returns "bceb6963-b1b7-4ced-9075-423ce6135921"

 

 

 

so basically it would look like this?

 

if (preg_match('/video\/(.*)\.htm', $this->_mediaInfo['url'], $match) {

Link to comment
Share on other sites

You could use something like the following to determine if it has a - in it.  If you wanted to split the string based on -'s you could use explode (http://php.net/explode).

if(strpos($url, "-") !== false) {
//its a streetfire url... or well... it has a - in it anyway ;p
}

 

Edit: forgot to answer your question.

 

so basically it would look like this?

 

if (preg_match('/video\/(.*)\.htm', $this->_mediaInfo['url'], $match) {

 

That would be the basic syntax of it, but that regexp is incorrect.  It will generate a warning ;p.

 

It would interpret / as a delimiter instead of the the beginning of /video/.

 

You could use something like "/\/video\/(.*)\.htm\/", but the regexp you said would not work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.