str_replace of html using php
I have this code:
$newphrase = str_replace('href="/Css/IE6.css"', 'href="http://www.company.com/pgrddedirect/iefix.c开发者_运维技巧ss"', 'href="/Css/IE6.css"');
So that I can search the html file in php using DOM in an attempt to modify the location of the .css file before I redisplay it. I intend on uploading the new .css file to my server and when I display the page with my php I want to first edit the location lines of the css so that I can resdisplay it with my own. The code can find and edit the html but I don't know how to save it before displaying it.
Cheers
Why can't you just change the actual link manually (wherever it's defined)?
This is a lot of overhead, especially if your page is big.
This is how str_replace works:
mixed str_replace ( mixed $search , mixed $replace , mixed $subject
So do this:
$newdata = str_replace('href="/Css/IE6.css"', 'href="http://www.company.com/pgrddedirect/iefix.css"', $data);
Where $data is a string containing the original HTML.
精彩评论