Extending that simple little example with some meaty text and some PHP, you end up with something like this:
$text = ”
\”stuff\”, watch out!
$text = preg_replace(“/\s+/”,” “,$text);
$text = preg_replace(‘/\\”/’,”””,$text);
document.write(‘<?php echo $text; ?>’);
That solution works (at least, it did before I had to replace all the tags with html entities to make this post). The text gets written at that point in the document once it loads on the client-side. Notice that the regular expressions replace double-quotes with 2 single quotes (tricky, eh?), and any excessive space is replaced. But what if you want something more complicated… what if you don’t like the regular expressions and having to escape your double-quotes? The above method is sorta techie for some, and prone to error. There is another solution: use an Ajax library to pipe HTML directly to a div tag. This solution is more scalable because you can put all the HTML in a separate file, and you don’t have to escape characters.
new Ajax.Updater('target_div', 'include_file.php');