Question

I was changing css file urls like str_replace('url(', 'url(somelocation/', $content); now I want to exclude, absolute path ones, like url(/ does any one suggest something?

Was it helpful?

Solution

preg_replace('@url\(([^/].*)\)$@', preg_quote($location) . '$1', $content);

OTHER TIPS

$location = 'somelocation'; // or however you're getting somelocation
if (strpos($location, '/') === 0) {
    $location = substr($location, 1);
}
str_replace('url(', 'url(' . $location, $content);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top