preg_replace multiple problem
I am trying to replace multiple urls in a pagination element with a new url.
The replacement works fine when there is one occurrence of the url i.e. prev and next, but it breaks on breaks on the Paginat开发者_JAVA技巧ion Numbers. It brings the first and last number links together. How do I get the preg_replace function realize that there are multiple occurrences of the links that need replacing?
<?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')));
?>
Try this:
$pattern = '/\/(.+?)\/page:(\d)/S';
Your .+ is greedy. In other words, it's sucking up everything between the first / and the last /page:.
The ? operator will make it match the minimum instead.
精彩评论