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
Share on other sites

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.

Link to comment
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
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
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.