$contents = 'url("/test/what)';
echo preg_replace('/url\(([\'"]?)(?!(?:[a-z]+:)|\/|[\'"]\/)/i', 'url(\1'. '/prefix' . '\2', $contents);
I want to append /prefix
to those urls that didn't use absolute path(start with /
), the above works, but is pretty ugly.
Is there a more elegant solution?