level9wizard
asked on
PHP & Regex : Replace entire <head>
I'm storing an entire html page in $html. I need to replace everything from <head> to </head> with my own $head (so either the stuff inside is replaced, or the stuff inside and the tags - whichever makes more sense). How can I do this?
$html = preg_replace("|<head>(.*)< /head>|m", $newhead,$ html);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please look :
http://www.phpdig.net/ref/rn53re1100.html
http://php.about.com/od/advancedphp/ss/php_preg_4.htm
http://www.webcheatsheet.com/php/regular_expressions.php
http://www.php-learn-it.com/tutorials/php_string_replace.html
This will help you.
regards