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


Similar Posts