preg_replace only replaces first occurrence then skips to next line
Posted
by Dom
on Stack Overflow
See other posts from Stack Overflow
or by Dom
Published on 2010-06-06T16:23:15Z
Indexed on
2010/06/06
16:32 UTC
Read the original article
Hit count: 236
Got a problem where preg_replace only replaces the first match it finds then jumps to the next line and skips the remaining parts on the same line that I also want to be replaced.
What I do is that I read a CSS file that sometimes have multiple "url(media/pic.gif)" on a row and replace "media/pic.gif" (the file is then saved as a copy with the replaced parts). The content of the CSS file is put into the variable $resource_content:
$resource_content = preg_replace('#(url\((\'|")?)(.*)((\'|")?\))#i', '${1}'.url::base(FALSE).'${3}'.'${4}', $resource_content);
Does anyone know a solution for why it only replaces the first match per line?
© Stack Overflow or respective owner