AaronCameron.net
I can't believe how tired I am.
Not a Member? - Login or Create an Account...MC Offline
Tuesday the 19th of September 2017 @ 11:03am
Front Page Projects Your Profile About
[]

PHP Simple Source Highlighter Examples

This page contains sample conversions of some simple source code, showing off C/C++, and PHP. Right now bash scripts are treated as plain text. It's on the list of things to do.

C/C++ Highlighting

0001 class cBuffer;	// This is defined somewhere else
0002 class cMyClass
0003 {
0004 public:
0005 	cMyClass( cAutoPtr<cBuffer> io_aBuffer ) :
0006 		m_buffer( io_aBuffer ) { }
0007 private:
0008 	cAutoPtr<cBuffer> m_buffer;
0009 }
0010 
0011 int main()
0012 {
0013 	cAutoPtr<cBuffer> buf = new cBuffer; // +1
0014 	cMyClass * c = new cMyClass( buf ); // +1
0015 	cMyClass * d = new cMyClass( buf ); // +1
0016 
0017 	// Use our classes a bit
0018 	delete c;  // (buf is still ok, count is 2 now)
0019 	
0020 	buf = new cBuffer("Hello World!");
0021 	// Our d instance is still ok, the original auto
0022 	// pointer gave up its reference, but d is still
0023 	// using it, so it isn't deleted yet.
0024 
0025 	// Do some more stuff
0026 
0027 	buf = 0;	// Nothing is using the new buf, 
0028 			// it gets deleted.
0029 
0030 	delete d;	// -1, our original buf is no longer
0031 			// pointed to by anything, and gets
0032 			// deleted.
0033 }
0034  

PHP Highlighting

0001 	// Everything we wrote up till now is above here
0002 
0003 	$server = "ftp.my.hosting.company";
0004 	$ftpFp = ftp_connect( $server );
0005 	if (!$ftpFp) {
0006 		echo "Couldn't connect to my FTP server: ".
0007 			"\"$server\"\n";
0008 		return 1;
0009 	 }
0010 
0011 	// Put the connection in passive mode.  
0012 	// Most servers behind a firewall
0013 	// will need this to work.
0014 	ftp_pasv($ftpFp,true);
0015 	
0016 	// Log in
0017 	$user = "my_ftp_user";
0018 	$password = "my_ftp_password";
0019 	$loginOk = ftp_login( $ftpFp, $user, $password );
0020 	if (!$loginOk) {
0021 		echo "Couldn't login to FTP server using: "
0022 			"\"$user\" and a password.\n";
0023 		return 1;
0024 	 }
0025  

©2017 Aaron Cameron