wish to replace some words quickly on my small website.

$pattern = '/bWordb/i' $content = preg_replace($pattern,'Replacement',$content)

That actually works to date. However i would like just have to change the what that are inside div id="content"

How do you do this?

When the submissions are dynamically driven then just echo the return worth of $content in to the div with id of content. When the submissions are static then you will need to either make use of this PHP snippit around the text then echo the return in to the div, or use JavaScript (dirty method!).

$content = "Your string of text goes here";

$pattern = '/\bWord\b/i';

$content = preg_replace($pattern,'Replacement',$content);

<div id="content">

<?php echo $content; ?>


$dom = new DOMDocument();

$x = new DOMXPath($dom);
$pattern = '/foo/';
foreach($x->query("//div[@id='content']//text()") as $text){
   $occurances = array_reverse($occurances[0]);
   foreach($occurances as $occ){
   //alternative if you want to do it in one go:
   //$text->parentNode->replaceChild(new DOMText(preg_replace($pattern,'oof',$text->wholeText)),$text);
echo $dom->saveHTML();
//replaces all occurances of 'foo' with 'oof'
//if you don't really need a regex to match a word, you can limit the text-nodes 
//searched by altering the xpath to "//div[@id='content']//text()[contains(.,'searchword')]"

use the_content filter, you can put it inside your styles function.php file

add_filter('the_content', 'your_custom_filter')

function your_custom_filter($content) 

UPDATE: This is applicable only when you're using WordPress obviously.