getting character from a name

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

getting character from a name

Post 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
Last edited by danwguy on Wed Mar 16, 2011 2:20 pm, edited 1 time in total.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: getting character from a name

Post by AbraCadaver »

Lot's of ways. Here's one that comes to mind:

Code: Select all

$number = preg_replace('/[^\d]*/', '', basename($_SERVER["SCRIPT_NAME"]));
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: getting character from a name

Post 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.
Post Reply