Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    91
    Thanks
    8
    Thanked 0 Times in 0 Posts

    getting substring name

    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...klfjdskldfd=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.

  • #2
    New Coder
    Join Date
    Jan 2011
    Posts
    91
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Code:
    $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

  • #3
    New Coder
    Join Date
    Jan 2011
    Posts
    91
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Hey, sorry for the post. I got it resolved. I was supposed to use
    Code:
    $lastIndex = strrpos($myURL, '/', 0);
    instead of
    Code:
    $lastIndex = lastIndexOf($myURL,'/');
    .

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Yes, but.
    You'll need to determine if the results of the strrpos are valid or not. Use an if check for that:
    PHP Code:
    if (false !== $lastIndex)
    {
        
    $myURL substr($myURL0$lastIndex);

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •