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.

Recommended Answers

Check out the parse_url method. php docs

$myurl = "http://www.mystore.website.com/index.php?fkdsjklfjdskldfd=id";
$myvar = parse_url($myurl);

Also if your problem is solved please mark the thread as …

Jump to Post

echo $_SERVER["HTTP_HOST"].$_SERVER['php_self']

Jump to Post

All 6 Replies


I am doing like this

        $lastIndex = lastIndexOf($myURL,'/');
        $myURL = substr($myURL,0,$lastIndex);
        //echo $myURL;

But nothing is happening. instead of '/' what i can use ... plz help

Hey, sorry for the post. I got it resolved. I was supposed to use $lastIndex = strrpos($myURL, '/', 0); instead of $lastIndex = lastIndexOf($myURL,'/');.

echo $_SERVER["HTTP_HOST"].$_SERVER['php_self']

Member Avatar

Second the parse_url().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.