I want to extract numbers from an array, the array is an url. The url is for instance www.hostname.com/dir/47.php or /dir/1324.php and so on. The code I made works fine by doing this, but I'm no PHP wizkid. Is there a more easy way to extract the numbers from the url? Here is the code I made: <? $dir = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $link = eregi_replace("www.hostname.com/dir/", "", $dir); $no = eregi_replace(".php", "", $link); require_once("http://www.hostname.com/dir/index.php?c=$no"); ?> Code (markup):
I'd do this.. $no = substr(basename($_SERVER['PHP_SELF']),0,-4); require_once("http://www.hostname.com/dir/index.php?c=$no"); PHP: