add CDATA to script- and style-tags via regex using PHPs output buffering


/ Published in: PHP
Save to your folder(s)

This snippet can be used to sanitize HTML when delivering it as XHTML. For example Firefox 2 needs XML-data to not mess up with HTML5-tags.
Everything (at least there must be one character) between script/style-tags is enclosed by a CDATA-block.
The whole functionality is provided as a callback function to `ob_start()`, which should be used before any output. The use of `ob_flush()`, `ob_clean()` or something is optional as the buffer will be sent on script end anyway.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.