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
Stop manually refreshing your browser on every code change and start increasing your development productivity with LiveReload 2!
In this interview I open up about what it was like to help organize WordCamp San Diego and our newest product release: Give. Check it out and give er’ a listen.
WordPress 3.0’s menu system already rocks, but check out what you can do with this GoDaddy-like menu system with custom “walkers” containing descriptions.
The Roots Theme for WordPress is awesome for creating great websites. I’ve built many of the sites in my portfolio on Roots and actually have one showcased in the Roots Gallery (Vets2Go). One situation I come across every so often is the need to reverse the logic of the Roots sidebar. Roots Sidebar Explanation Roots…
Experiencing slowness with you Windows 8 system using XAMPP or DesktopServer? Here’s a fix I found that sped me up 5x.
The jQuery UI tabs ‘select’ event and some minor Javascript makes changing the hashtags of the url to the current tab’s hashtag very easy.