Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-20-2012, 05:57 AM   PM User | #1
Mythri
New Coder

 
Join Date: Jan 2011
Posts: 70
Thanks: 8
Thanked 0 Times in 0 Posts
Mythri is an unknown quantity at this point
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.
Mythri is offline   Reply With Quote
Old 07-20-2012, 06:26 AM   PM User | #2
Mythri
New Coder

 
Join Date: Jan 2011
Posts: 70
Thanks: 8
Thanked 0 Times in 0 Posts
Mythri is an unknown quantity at this point
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
Mythri is offline   Reply With Quote
Old 07-20-2012, 06:40 AM   PM User | #3
Mythri
New Coder

 
Join Date: Jan 2011
Posts: 70
Thanks: 8
Thanked 0 Times in 0 Posts
Mythri is an unknown quantity at this point
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,'/');
.
Mythri is offline   Reply With Quote
Old 07-20-2012, 02:37 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:07 AM.


Advertisement
Log in to turn off these ads.