hi i have this link: http://forum.te3p.com/314972.html Code (markup): i need to get the number before .html extension. so my regex pattern should get only the number.. here is my code: $url = 'http://forum.te3p.com/'; $pattern_url = str_replace('/',"\/",$url); $pattern_url = str_replace('.',"\.",$pattern_url); if(preg_match_all("/$pattern_url([0-9]*?)\.html/", $s, $t)) PHP: any help would be appreciated...
$input = 'http://forum.te3p.com/314972.html'; $url = 'http://forum.te3p.com/'; if (preg_match_all('/' . preg_quote($url, '/') . '([0-9]*)\.html/iU', $input, $matches, PREG_SET_ORDER)) { } PHP:
Use this: $url = 'http://forum.te3p.com/314972.html'; preg_match_all('/\/([0-9]+)\./Usm',$url,$results); print_r($results); PHP:
Why would you not use parse_url, and then just strip off everything else. $parsed_url = parse_url('http://forum.te3p.com/314972.html'); $numbers = (int)$parsed_url['path']; Or if there are potentially zero's you could do. $numbers = substr(1,strpos('.',$parsed_url['path'] -2),$parsed_url['path']);