Sign in to follow this  
Evil Steve

[web] PHP C++ parser?

Recommended Posts

Evil Steve    2017
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
Rob Loach    1504
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:


<?php

////////////////////////////////////////////////////////////
// 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()) .
"</p>";
} else{
echo "<h1>Source View</h1><p>The given file does not exist (<a href='$file' target=_blank>$file</a>).</p>";
}

?>





[example]

Share this post


Link to post
Share on other sites
Evil Steve    2017
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.

Cheers,
Steve

Share this post


Link to post
Share on other sites
Rob Loach    1504
Quote:
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.

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

ActionScript
ASP
Assembly (NASM)
C++
javascript
Perl
Python
XML

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this