preg_match('#([A-Za-z0-9]{10})$#', $url, $matches);
In short: [A-Za-z0-9]
takes any alphanumeric character, ucase and lcase both allowed, {10}
requires it exactly 10 times, and $
requires it to be at the end of the string. The parentheses (
and )
define which part(s) you want to get back in the 3rd $matches
output variable. Finally it's all surrounded by 2 #
's as regex delimiters.
Now go read every article in the left sidebar of this page so you can do it yourself next time :)