bms231 Posted May 3, 2007 Share Posted May 3, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/49737-help-with-a-regex-expression/ Share on other sites More sharing options...
corbin Posted May 3, 2007 Share Posted May 3, 2007 $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" Quote Link to comment https://forums.phpfreaks.com/topic/49737-help-with-a-regex-expression/#findComment-243899 Share on other sites More sharing options...
bms231 Posted May 3, 2007 Author Share Posted May 3, 2007 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 - Quote Link to comment https://forums.phpfreaks.com/topic/49737-help-with-a-regex-expression/#findComment-243900 Share on other sites More sharing options...
bms231 Posted May 3, 2007 Author Share Posted May 3, 2007 $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) { Quote Link to comment https://forums.phpfreaks.com/topic/49737-help-with-a-regex-expression/#findComment-243901 Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 Make sure to define the variables also. Quote Link to comment https://forums.phpfreaks.com/topic/49737-help-with-a-regex-expression/#findComment-243924 Share on other sites More sharing options...
corbin Posted May 3, 2007 Share Posted May 3, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/49737-help-with-a-regex-expression/#findComment-243929 Share on other sites More sharing options...
bms231 Posted May 3, 2007 Author Share Posted May 3, 2007 Make sure to define the variables also. i am looking to do it though w/o declairing the var... like the example i posted. which i think does not work b/c it breaks. Quote Link to comment https://forums.phpfreaks.com/topic/49737-help-with-a-regex-expression/#findComment-243933 Share on other sites More sharing options...
corbin Posted May 3, 2007 Share Posted May 3, 2007 Umm so wait, which variable are you trying to not define? I'm confused ;p. Quote Link to comment https://forums.phpfreaks.com/topic/49737-help-with-a-regex-expression/#findComment-243937 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.