View Single Post
Old 09-06-2012, 01:35 AM   PM User | #3
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
So if you are unfortunate enough to be stuck with PHP < 5.2.4 then you can use the following to colour keywords blue, but NOT if they occur after // comment delimiters:

PHP Code:
function onlyWholeWords(&$value$key) {
    
$value "/^((?:(?!\/\/).)*)\b" $value "\b/";
}
function 
addSpan(&$value$key) {
    
$value "$1<span style='color:blue'>" $value "</span>";
}
function 
codeWords($code) {
    
$words = array('break''case''class''continue''default''do''elif'
        
'else''for''function''if'
        
'new''null''return''self''switch''this''typeof'
        
'var''void''while''with');
    
$words2 $words;

    
array_walk($words'onlyWholeWords');
    
array_walk($words2'addSpan');
    
$code preg_replace($words$words2$code);
    return 
$code;

Attached Thumbnails
Click image for larger version

Name:	blogs2.png
Views:	43
Size:	5.3 KB
ID:	11523  
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 09-06-2012 at 01:40 AM..
AndrewGSW is offline   Reply With Quote