Imagine I have a string, $my_css_string, and we know it contains CSS styling.
Now imagine I have a function string url_replace(string $url) that returns a modified URL that I want to replace every url() with in $my_css_string.
So, for simplicity's sake, let's say url_replace() ALWAYS returns the string "xxxx".
How can you go through $my_css_string, find each url() in the string, and replace that URL with what you get from url_replace()?
So, if you had this CSS as $my_css_string:
@import url('http://example.com/css/animals.css');
.dog {
background:url("/images/dog.png");
border:1px solid rgb(0,0,128);
}
.cat {
background:url(http://example.com/images/cat.gif);
}
If you ran the code, $my_css_string would become:
@import url('xxxx');
.dog {
background:url( "xxxx" );
border:1px solid rgb(0,0,128);
}
.cat {
background:url(xxxx);
}
Notice how it needs to handle multiple ways of defining URLs.
How do I do that?