Jump to content
  • Advertisement
Sign in to follow this  
Evil Steve

[web] PHP C++ parser?

This topic is 5384 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, does anyone have a PHP script that will take in C++ code, and spit out coloured HTML that I could steal? Basicly exactly what the [ source ] tags here on GDNet do. Cheers, Steve

Share this post

Link to post
Share on other sites
You can attempt to use the Highlight File function. It's made for PHP but it might also work for C++.

Here's a little function/file I wrote up to output it nicely:


// Title: PHP Source Code Display
// Author: Rob Loach (http://robloach.net)
// Description:
// A script which just displays the source of the
// given file.

// The file to display
$file = "/file.php";

// Extensively checks if a file exists
function file_exists_incpath ($file)
$paths = explode(PATH_SEPARATOR, get_include_path());
foreach ($paths as $path)
$fullpath = $path . DIRECTORY_SEPARATOR . $file;
if (file_exists($fullpath)) {
return true;
return false;

// See if the file exists
if (file_exists_incpath($file)){

// Display the source
echo "<h1>Source View</h1><p>Source of <a href='$file' target=_blank>$file</a>:</p>
<hr/><code>" .
highlight_file("$file", true) .
"</code><hr /><p>Processed: " .
date("F j, Y g:i:s a", time()) .
} else{
echo "<h1>Source View</h1><p>The given file does not exist (<a href='$file' target=_blank>$file</a>).</p>";



Share this post

Link to post
Share on other sites
Yeah, I thought about using that, but theres bound to be some things that won't work right. I'll give it a go and see how it looks.


Share this post

Link to post
Share on other sites
Original post by DerAnged
It just does not yet parse c++, or c++ keywords sutch as class.

I'm currently working on a C++ language file for Geshi. It doesn't have everything in it as C++ is just such a huge language, but it has the basic stuff. Still in construction. If you guys have anything to add to it, please help me out and tell me.

[Demo] [Source] [Download]

You have to put the file in the geshi directory and then set $language to "cpp" when you're using it.

Originally from the Geshi Forums
The following languages from your list will already be supported in 1.0.2:

Assembly (NASM)

In addition, some of the languages you list above, like Transact-SQL, can be substituted for by the plain SQL file.

Also, some other languages you've missed, like Bash and VisualFoxPro will be supported.

Well, until then, mine'll work [wink].

[Edited by - Rob Loach on October 20, 2004 2:11:29 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!