-
PHP parsing Problem
Hey, was looking for a bit of php help for a page I'm making. Just as a note I'm learning php currently but I'm not great at it so any help would be great.
Heres what I want to do;
the page URL is:http://www.whatever.com/whatever.php/123
now I'm trying to make a php program that will grab the path info, so what's in the URL bar and parse out 123, or for that matter any other number that is at the end. Then simply input it into a variable called $newsart. I've tried a few different ways and have been told that in newer version of php the function for grabbing that path info has changed. Does anyone have any suggestions?
-script
-
Re: PHP parsing Problem
Is there not a way of doing this?
-
Re: PHP parsing Problem
Try like:
PHP Code:
$url = "http://www.whatever.com/whatever.php/123";
$parts = explode($url, "/");
$number = $parts[sizeof($parts)];
print $number;
I wrote that by hand, so test it out :p
-
Re: PHP parsing Problem
Alright but I need a way to grab the numbers from the URL no matter what they are.
-script
-
Re: PHP parsing Problem
That does. Explode splits a string up depending on a certain element, like "/" and returns all the parts in an array. The last part would be the number, because it's after the last "/", and sizeof returns the number of elements an array holds, thus we are getting the last element from the array, which is the number.