Jump to content

Quick regex question


bms231

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/52172-quick-regex-question/
Share on other sites

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)) {

Link to comment
https://forums.phpfreaks.com/topic/52172-quick-regex-question/#findComment-257793
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/52172-quick-regex-question/#findComment-258057
Share on other sites

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.