2009-10-14 153 views
0

我想用新的url替换分页元素中的多个网址。preg_replace多个问题

当网址出现一次(即上一页和下一页)时,替换工作正常,但它在分页编号上出现中断。它将第一个和最后一个号码链接放在一起。如何让preg_replace函数意识到有多个需要替换的链接出现?

<?php 
    $pattern = '/\/(.+)\/page:(\d)/S'; 
     $replacement = $uurl.'page:$2'; 
     echo preg_replace($pattern, $replacement,$paginator->prev('<< '.__('previous', true), array('url' => $paginator->params['pass']), null, array('class'=>'disabled'))).' | '; 
     echo preg_replace($pattern, $replacement,$paginator->numbers()); 
     echo preg_replace($pattern, $replacement,$paginator->next(__('next', true).' >>', array('url' => $paginator->params['pass']), null, array('class'=>'disabled'))); 
    ?> 

回答

4

试试这个:

$pattern = '/\/(.+?)\/page:(\d)/S'; 

你+是贪婪。换句话说,它吸收了第一个/和最后一个/页面之间的所有内容:

The?操作符会使其与最小值相匹配。

+0

这没有奏效。 – jbrass 2009-10-17 00:52:19