News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Chris Shiflett's Blog:
Formatting and Highlighting PHP Code Listings
October 27, 2006 @ 07:19:00

In his continuing effort to redesign his blog, Shiflett.org, he's been working on one of the things that really makes a blog useful - the commenting system. Specifically, he wants site visitors to be able to add their own code listings to the comments they post. He gives more detail in this new post.

I've been playing with this tonight. Feel free to follow along as I go. The first thing you want to do is create an ordered list from the code you want to format ($code in these examples).

He gives an example of a listing using his system and explains how it all works. It's a mixture of:

  • PHP for parsing the data inside the 'code' tags
  • CSS to correctly style the information, whitespace and all
  • Some ini settings to set parameters for...
  • ...the use of highlight string on the PHP code contents
A little str_replace magic later and you have list items styled as code blocks on your page. Check out his demo for an example.

1 comment voice your opinion now!
format highlight listing comment blog highlight_string css format highlight listing comment blog highlight_string css


blog comments powered by Disqus

Similar Posts

Sandro Groganz's Blog: Syntax Highlighting & Migrating Permalinks in WordPress

Sander Marechal's Blog: A YuiCompressorFilter for Phing

SitePoint PHP Blog: Commenting, Upvoting and Uploading Photos with the 500px API

Community News: "Ideas of March" Kicks off a "Blogging Revival"

Padraic Brady's Blog: ZF Blog Tutorial Part 10: Comments, reCAPTCHA and Akismet Filtering


Community Events

Don't see your event here?
Let us know!


extension php7 library laravel series podcast version interview video laravel5 language api example introduction framework community security voicesoftheelephpant opinion release

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework