preg_replace only part of match

Posted by Tony Vipros on Stack Overflow See other posts from Stack Overflow or by Tony Vipros
Published on 2010-04-21T10:44:51Z Indexed on 2010/04/21 10:53 UTC
Read the original article Hit count: 376

Filed under:
|
|

Hi,

I'm using preg_replace to create urls for modrewrite based paging links. I use:

$nextURL = preg_replace('%/([\d]+)/%','/'.($pageNumber+1).'/',$currentURL);

which works fine, however I was wondering if there is a better way without having to include the '/' in the replacement parameter. I need to match the number as being between two / as the URLs can sometimes contain numbers other than the page part. These numbers are never only numbers however, so have /[\d]+/ stops them from getting replaced.

© Stack Overflow or respective owner

Related posts about php

Related posts about preg-match