Page 1 of 1

getting character from a name

Posted: Wed Mar 16, 2011 2:05 pm
by danwguy
so let's say I have a url that ends with stage3.php, I need to figure out a way to get just that 3 from the url. The other "problem" I guess I should say is, if the url ends in stage15.php then I need it to return the 15, not just the 1 or the 5. Any help would be greately appreciated. I am honestly not sure where to even start, since I am not sure how to retrieve it from the url without the $_GET command, and since it's not being passed as a variable I am not sure how to grab it. It could be something like sitename.com/stage15.php. Thank you for your help in advance and I hope I am making sense.

EDIT: So I was able to get the current page name using

Code: Select all

function curpage() {
return substr($_SERVER["SCRIPT_NAME"], strrpos($_SERVER["SCRIPT_NAME"], "/") +1);
}
now I just need to figure out how to get the numbers right before the period

Re: getting character from a name

Posted: Wed Mar 16, 2011 2:12 pm
by AbraCadaver
Lot's of ways. Here's one that comes to mind:

Code: Select all

$number = preg_replace('/[^\d]*/', '', basename($_SERVER["SCRIPT_NAME"]));

Re: getting character from a name

Posted: Wed Mar 16, 2011 2:22 pm
by danwguy
thank you so much for that. that saved me a ton of time coding a hidden input into a thousand freaking forms. Thank you, thank you and thank you.