How to get id from URL in PHP?

How to get only the id from a URL using wither PHP or htaccess …
For example,

http://www.example.com/blah-blah-blah-123.php

I want to get 123 (and similar entered id) from the url using get and post, I know using get and post methods, but i just want to get 123 from this url.

Thanks.

you can writ a regular expression to chop the blah-blah-blah part out.

Will you please show how to write regular expression for this?

can you show a few examples of urls? you can leave out the domain.

For the example URL it could be as simple as something like:



preg_match( '/([0-9]+)\\.php\\z/', $_SERVER[ 'REQUEST_URI' ], $matches );

// $matches[1] will contain the id


How to get the value of $matches?

$matches[1] will contain the id after preg_match() executes.

Thank you sir.
I understood.