简体   繁体   中英

better way for url change using str_replace, not regular expressions

我正在更改css文件的URL,例如str_replace('url(', 'url(somelocation/', $content);现在我想排除绝对路径,例如url(/有人建议吗?

preg_replace('@url\(([^/].*)\)$@', preg_quote($location) . '$1', $content);
$location = 'somelocation'; // or however you're getting somelocation
if (strpos($location, '/') === 0) {
    $location = substr($location, 1);
}
str_replace('url(', 'url(' . $location, $content);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM