bms231 Posted May 20, 2007 Share Posted May 20, 2007 I am a C# guy and wondering what LastIndexOf would be in php. Here is what I have and want to do...... Here are the two possible URLs. There is nothing really common. I need that id at the end w/o the htm. http://videos.xxxxxxxxxx.com/video/bceb6963-b1b7-4ced-9075-423ce6135921.htm http://videos.xxxxxxxxxx.com/search/tibn/0/9fdd173c-0b67-4236-815d-9933007664e0.htm here is what I had, if (preg_match('/\/video\/(.*)\.htm/', $this->_mediaInfo['url'], $match)) { well, that obviously only works for the /video/ and after. i need basically to get last index of / and then go from one plus / to . any ideas? Quote Link to comment Share on other sites More sharing options...
Orio Posted May 20, 2007 Share Posted May 20, 2007 I think you should leave regex aside and use explode(): <?php $temp = explode("/",$this->_mediaInfo['url']); $last = $temp[count($temp)-1]; $what_you_want = substr($last, 0, -4); //Remove the .htm ?> Haven't tested it, but it should work. Orio. Quote Link to comment Share on other sites More sharing options...
bms231 Posted May 20, 2007 Author Share Posted May 20, 2007 negative, that didnt really do it. i tried this, not working either. $pos = strrpos($this->_mediaInfo['url'], "/"); //$temp = explode("/",$this->_mediaInfo['url']); //$last = $temp[count($temp)-1]; $streetfirekey = substr($this->_mediaInfo['url'], $pos + 1, -4); //Remove the .htm if (preg_match($streetfirekey, $this->_mediaInfo['url'], $match)) { Quote Link to comment Share on other sites More sharing options...
bms231 Posted May 20, 2007 Author Share Posted May 20, 2007 bump. anyone? Quote Link to comment Share on other sites More sharing options...
Orio Posted May 21, 2007 Share Posted May 21, 2007 Look, I've tested this script and it worked, no regex as I said: <?php $urls = array("http://videos.xxxxxxxxxx.com/video/bceb6963-b1b7-4ced-9075-423ce6135921.htm", "http://videos.xxxxxxxxxx.com/search/tibn/0/9fdd173c-0b67-4236-815d-9933007664e0.htm"); foreach($urls as $url) { $temp = explode("/",$url); $last = $temp[count($temp)-1]; $what_you_want = substr($last, 0, -4); //Remove the .htm echo $what_you_want."<br>"; } ?> Orio. Quote Link to comment 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.