/    Sign up×
Community /Pin to ProfileBookmark

Format & Display Code

I’m working on my website, which will include code snippets. The article itself is stored in a db. Each piece of code is included in a class “code” div.
What I want to know is a method of formatting it, doing selective syntax highlighting (C++, PHP, HTML, etc – I can specify that in my div as a first line or something) and then displaying it nicely on the client side. This includes detecting long lines which go over the div.

Something like [url=http://programmabilities.com/xml/?id=15]this[/url] would be nice (I’m talking about the auto numbered lines, although it has no highlight). I’m sure there’s a script for this somewhere.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 28.2008 — PHP has the highlight_string() and highlight_file() functions which you might want to look at.
Copy linkTweet thisAlerts:
@scragarJul 28.2008 — firstly please note that there is a tag especialy designed for displaying code, it's quite litteraly the code tag:
[code=html]<code>some code or other</code>[/code]

secondly php's highlight_string function works great for PHP and javascript (and C/C++ to a lesser extent).

http://qbnz.com/highlighter/ <-- that's a nice code to do a lot of languages and make them styled, although I'm not too big a fan of the results it does reduce the code required.



EDIT: beat to it ?
Copy linkTweet thisAlerts:
@kvirriauthorJul 29.2008 — I'm not exactly into syntax_highlight, since I also need some assembly from time to time. GeSHi is what I need, wonderful piece of code. Thanks!
Copy linkTweet thisAlerts:
@LeeUJul 29.2008 — We use SyntaxHighlighter over on WebReference.com. It works great.
×

Success!

Help @kvirri spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...