Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

PHP Explode

I'm a little confused:

I'm trying to extract one part of a url, but am not succeeding.

URL: http://www.MYSITE.com/members/member-name/profile/

	$str = $_SERVER["REQUEST_URI"];
	$array = explode("/", $str, 3);
	$slug_a = $array[2];
	$slug = str_replace('/', '', $slug_a); 
	echo $slug;

Open in new window


Right now $slug is echoing "member-nameprofile"
I need it to only echo "member-name"

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gary
The 3 in your explode is limiting the array to only 3 elements, anything over that is just added to the last element of the array since the URI will begin with a slash you have a blank starting element in your array, change it to 4 or just do it the way Ray has.

edit.
Actually limiting it makes no sense in this case! Ray's way is the best way.