- htmlspecialchars: documentation ( source)
- preg_replace: documentation ( source)
<?php
$lt = '<';
$gt = '>';
$raw_data = '[if lte IE 8]><link href="//d3h5jhobc20ump.cloudfront.net/f521cb9cec0171e8d913538552d98b10.css" rel="stylesheet" type="text/css"><![endif]';
echo htmlspecialchars(preg_replace('/^\\s*\\[\\s*(if)(\\s[^\\]]*?)?\\s*\\]'.$gt.'\\s*(.*?)\\s*'.$lt.'!\\[\\s*(endif)\\s*\\]\\s*$/si', '[$1$2]'.$gt."\r\n".'$3'."\r\n".$lt.'![$4]', $raw_data));