Please note that the information in this post may no longer be accurate or up to date. I recommend checking more recent posts or official documentation for the most current information on this topic. This post has not been updated and is being kept for archival purposes.
I often need to replace the contents of a tag using php with another variable. This is made easy with the preg_replace() function and a nifty regular expression.
$content = 'Some content to replace'; echo $content; //output:Some content to replace//replace content using preg_replace and regex: $content = preg_replace('/]*>.*?<\/div>/i', 'New Content', $content); echo $content; // new output: //New Content
http://stackoverflow.com/questions/7139342/preg-replace-how-to-remove-contents-inside-a-tag