I’m going through an HTML file replacing all the references to external files with new ones, however, sometimes this results in errors.
For example: I want to replace all instances of styles.css with 1.css and all instances of iestyles.css with 2.css in this source code:
<html>
<link href="styles.css" />
<link href="iestyles.css" />
</html>
Once I’ve run str_replace("styles.css", "1.css", $html); the source code looks like this:
<html>
<link href="1.css" />
<link href="ie1.css" />
</html>
So when I run the second query, it doesn’t change the iestyles.css reference because it no longer exists. Is there a way around this? I guess I could invent an elaborate regular expression, but there are a lot of variables to consider because not all code is well formed.
Cheers
Just change the order: First replace
iestyles.csswith2.cssand then replacestyles.csswith1.css.If you are sure the filename is the only thing within the
href-attribut, you could also include the double quotes"