nerkn
nerkn

Reputation: 1982

better way for url change using str_replace, not regular expressions

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?

Upvotes: 0

Views: 489

Answers (2)

David
David

Reputation: 404

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

Upvotes: 1

Anthony Corbelli
Anthony Corbelli

Reputation: 877

$location = 'somelocation'; // or however you're getting somelocation
if (strpos($location, '/') === 0) {
    $location = substr($location, 1);
}
str_replace('url(', 'url(' . $location, $content);

Upvotes: 0

Related Questions