php - How can I stop str_replace replacing only part of a filename? -



php - How can I stop str_replace replacing only part of a filename? -

i'm going through html file replacing references external files new ones, however, results in errors.

for example: want replace instances of styles.css 1.css , instances of iestyles.css 2.css in source code:

<html> <link href="styles.css" /> <link href="iestyles.css" /> </html>

once i've run str_replace("styles.css", "1.css", $html); source code looks this:

<html> <link href="1.css" /> <link href="ie1.css" /> </html>

so when run sec query, doesn't alter iestyles.css reference because no longer exists. there way around this? guess invent elaborate regular expression, there lot of variables consider because not code formed.

cheers

just alter order: first replace iestyles.css 2.css , replace styles.css 1.css.

if sure filename thing within href-attribut, include double quotes "

$html = str_replace('"styles.css"', '"1.css"', $html); $html = str_replace('"iestyles.css"', '"2.css"', $html);

php regex str-replace

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -