For example, I want an expression that will use preg_replace() to cycle through html docs and change all the body tags (including attributes) to a comment (<!-- body variable begins here -->).
My concern is that there will be important code before or after the body tag that I want unchanged. It is impossible to plan on the number of characters of this code, so should I use ^ and $? Or should I just start and end the expression with /?
My code thus far is:
Code: Select all
<?php
$text = preg_replace("/^(<body+)(.*)>+$/", "<!-- body variable begins here -->", $text)
?>I added ^ and $, but the result was the same.