I AM LISTENING TO
|

WHAT I LIKE

Turn any bulb into a smart light – emberlight Create and Manage multiple isolated PHP environments with virtPHP
AMP     API     CSS     Development     HTML5     PHP    

Generic Syntax Highlighting with Regular Expressions in pure PHP



3. March 2016


Due to Google AMP (Accelerated Mobile Pages) , I have been looking for a way to effectively do Syntax Highlighting without Javascript in pure PHP.

I was about to write my own, when I found an older article from phoboslab. Thanks Dominic for saving me some time 😉 Its not perfect, but close enough.

A simple Syntax Highlighting Class that does just that. The class was not working with PHP 5.4.x+, as it uses  preg_replace() with the /e modifier.

It will not cover all, but its better than nothing 🙂 I will also add a section to my my AMP tweaks article to showcase the integration of Geshi.

Here an updated version using the preg_replace_callback() function.

THE SYNTAX HIGHLIGHT CLASS

THE CSS

USAGE

@GitHub portalzine/UtilityBelt/SyntaxHighlight

Enjoy coding …




Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz