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.

Hi,

I am doing like this

$myURL = $_SERVER['REQUEST_URI'];
        $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,'/');.

Check out the parse_url method. php docs

<?php
$myurl = "http://www.mystore.website.com/index.php?fkdsjklfjdskldfd=id";
$myvar = parse_url($myurl);
echo($myvar['host']);
?>

Also if your problem is solved please mark the thread as solved, thank you.

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

$urlIn = 'http://www.abc.com/index.php?a=haha&b=hoho';
$arr = explode('?',$urlIn); //$arr['0']='http://www.abc.com/index.php' $arr['1']='a=haha&b=hoho'
echo $arr['0'];

like this?

Member Avatar for diafol

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 meeting, networking, learning, and sharing knowledge.