I am trying to match this uri. Also I want 3 to match as id and 45 in pictures45.html as pagenumber. /category/3/pictures45.html HTML: With this regex I got to match the category and id. preg_match("/^\/category\/(?P<id>\d+)/", $url, $matches); PHP: With this regex I got to match the pagenumber. preg_match("/(?P<pagenumber>\d).html/", $url, $matches); PHP: I figured I can combine both the regex and it should work but I can't get it to work. preg_match("/^\/category\/(?P<id>\d+)(?P<pagenumber>\d).html/", $url, $matches); PHP: What am I doing wrong? Thanks guys
This works but the regexp doesn't look so "good" <?php $url = '/category/3/pictures45.html'; preg_match('/\/category\/([0-9]+)\/([a-z]+)([0-9]+)/i', $url, $match); echo('<pre>' . print_r($match, true) . '</pre>'); $id = $match[1]; $pagenumber = $match[3]; echo ('<p> ID = ' . $id . '</p>'); echo ('<p> Page number = ' . $pagenumber . '</p>'); ?> PHP: