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

Similar Posts