I have a css declaration
background: url(corners/bl.png) no-repeat left bottom !important;
and I need to add something before corners/bl.png using preg_replace
The problem is that I also have
background: url(../images/gray/topmenu/active_l.png) no-repeat left center;
and I need to skip this because it’s contain ../ inside the url value.
What I need is to get the url value when the value is not containing ../ inside it. If it only contain / then get it and replace it, if ../ skip it.
here is the code which is working, except the ../ issue
$new_file_content = preg_replace(“/(:|,)(\s*?.?\s?)(\s*\burl)(\s*()([‘|\”]?)([^/|^’|^\”|^)]*)([‘|\”]?)())/i”, ‘$1$2$3$4$5’.implode(“/”,$file_path_explode).”/”.’$6$7$8′, $new_file_content);
I know I need to add another condition instead of
([^/|^’|^\”|^)]*)
but I can’t figure it out how to add something like except ../ [^(../)] or…?
Thanks
Would doing something like:
$new_file_content = preg_replace("/url\([\s]*(([^\.]{2})[^\)]+)/i", "url(". implode("/",$file_path_explode) ."/$1", $new_file_content);Fit what you need? It checks for the ‘url(‘ specifically so you are only touching what you actually want to replace within your regex. Also won’t match anything that starts with
url(.