CHECKING STATUS
I AM LISTENING TO
|

Generic Syntax Highlighting with Regular Expressions in pure PHP

5. February 2016
.SHARE

Table of Contents

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

Let’s Talk!

Looking for a reliable partner to bring your project to the next level? Whether it’s development, design, security, or ongoing support—I’d love to chat and see how I can help.

Get in touch,
and let’s create something amazing together!

RELATED POSTS

Overview The best approach is to create a minimal kiosk setup that: Hardware Requirements Setup Guide 1. Start with a Minimal OS Installation Rather than using the full Raspbian Desktop version, start with Raspbian Lite for a minimal footprint. This reduces overhead and security concerns by eliminating unnecessary software. Download Raspberry Pi OS Lite from […]

Directus is a powerful headless CMS that provides a flexible data platform with a beautiful admin app for managing content. In this guide, we’ll walk through the process of setting up Directus on your own server using Docker and Docker Compose. Introduction Directus wraps any SQL database with a real-time GraphQL+REST API and an intuitive […]

<sarcasm start> Hey there, future app builder! Remember when creating websites and apps required a computer science degree and endless nights of debugging? Those days are history! Are they ? :) Welcome to the golden age of NoCode platforms, where anyone with a brilliant idea can bring it to life without writing a single line […]

Alexander

I am a full-stack developer. My expertise include:

  • Server, Network and Hosting Environments
  • Data Modeling / Import / Export
  • Business Logic
  • API Layer / Action layer / MVC
  • User Interfaces
  • User Experience
  • Understand what the customer and the business needs


I have a deep passion for programming, design, and server architecture—each of these fuels my creativity, and I wouldn’t feel complete without them.

With a broad range of interests, I’m always exploring new technologies and expanding my knowledge wherever needed. The tech world evolves rapidly, and I love staying ahead by embracing the latest innovations.

Beyond technology, I value peace and surround myself with like-minded individuals.

I firmly believe in the principle: Help others, and help will find its way back to you when you need it.