...

View Full Version : getting substring name



Mythri
07-20-2012, 06:57 AM
Hi,

I am using `$_SERVER['REQUEST_URI'] ;` to get the complete URL address, but in that i want to take only the half, example in `$_SERVER['REQUEST_URI'] ;` i get http://www.mystore.website.com/index.php?fkdsjklfjdskldfd=id...
but i want to take only till http://www.mystore.website.com, how can i do it?

In PHP is there any function called LastIndex and Substing to use? I am confused. Please help me.

Mythri
07-20-2012, 07:26 AM
$myURL = $_SERVER['REQUEST_URI'];
$lastIndex = lastIndexOf($myURL,'/');
$myURL = substr($myURL,0,$lastIndex);
//echo $myURL;

I am using it like this. is it right?
Nothing is happening

Mythri
07-20-2012, 07:40 AM
Hey, sorry for the post. I got it resolved. I was supposed to use
$lastIndex = strrpos($myURL, '/', 0); instead of
$lastIndex = lastIndexOf($myURL,'/');.

Fou-Lu
07-20-2012, 03:37 PM
Yes, but.
You'll need to determine if the results of the strrpos are valid or not. Use an if check for that:


if (false !== $lastIndex)
{
$myURL = substr($myURL, 0, $lastIndex);
}

Since 0 is a valid offset position, you must check for identical to false.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum