Created
May 7, 2013 07:06
-
-
Save hilyjiang/5530752 to your computer and use it in GitHub Desktop.
高亮XML代码的函数,CodeIgniter Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 高亮XML代码 | |
if ( ! function_exists('xml_highlight')) | |
{ | |
function xml_highlight($s) | |
{ | |
$s = htmlspecialchars($s); | |
$s = preg_replace("#<([/]*?)(.*)([\s]*?)>#sU", "<span style=\"color:#0000FF\"><\\1\\2\\3></span>",$s); | |
$s = preg_replace("#<([\?])(.*)([\?])>#sU", "<span style=\"color:#800000\"><\\1\\2\\3></span>",$s); | |
$s = preg_replace("#<([^\s\?/=])(.*)([\[\s/]|>)#iU", "<<span style=\"color:#808000\">\\1\\2</span>\\3",$s); | |
$s = preg_replace("#<([/])([^\s]*?)([\s\]]*?)>#iU", "<\\1<span style=\"color:#808000\">\\2</span>\\3>",$s); | |
$s = preg_replace("#([^\s]*?)\=("|')(.*)("|')#isU", "<span style=\"color:#800080\">\\1</span>=<span style=\"color:#FF00FF\">\\2\\3\\4</span>",$s); | |
$s = preg_replace("#<(.*)(\[)(.*)(\])>#isU", "<\\1<span style=\"color:#800080\">\\2\\3\\4</span>>",$s); | |
return str_replace("\n", '<br style="height:0" />', $s); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment