Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php highlight html code 1

Status
Not open for further replies.

tiamat2012

Programmer
Dec 12, 2004
144
US
Does anyone know an easy function or script to highlight html? I'm looking for something similar to the php highlight, except for HTML, and I know there are several packs of script that do this, but it seems like a lot more work than necessary, and would like a simpler way then uploading all that data.

-Kerry
 
Holy shiza! It worked! I totally wasn't expecting it to, that was it, needed the full root!

Thank you so much for your help, would have been a fish out of water otherwise!

Many thanks,
Kerry
 
not so much the full root - it's just that readfile tries to open the file outside of the webserver (i.e. no parsing) whereas what you want is to get php to do its thang on the chip.php file.

enjoy!
 
I realized I hadn't tried it with &override, when I did it stopped working, but I found a solution.

Original code:
Code:
//this code block changed by justin adie on  6/4/06
if (!isset($_GET['override'])):
	$urlprefix = "[URL unfurl="true"]http://{$_SERVER[/URL]['SERVER_NAME']}";
	else:
	$urlprefix="//{$_SERVER['DOCUMENT_ROOT']}";
	$urlprefix = str_replace("///", "//", $urlprefix);
	endif;
//end code block change
}

new code:
Code:
	//this code block changed by justin adie on  6/4/06
	if (!isset($_GET['override']))
	{
		echo "Working so far <br />";
		$urlprefix = "[URL unfurl="true"]http://{$_SERVER[/URL]['SERVER_NAME']}";
	}	else
	{
		$urlprefix="{$_SERVER['DOCUMENT_ROOT']}";
		$urlprefix = str_replace("///", "//", $urlprefix);
	}
	//end code block change

I think it still has the same function (though I'm not totally sure what it is), it all works now!

-Kerry
 
not sure what you have done. but i'm glad it's working for you.

the old code and new code don't have quite the same function although they have the same aim.

the new code works over linux + windows. but it is not quite my coding style as i tend to use the
Code:
if (expression):
 //do something
else:
  // do something
endif;

note the colons and the endif. i find this structure easier to debug. however in a previous post sleipnir214 (who appears to have enormously more experience than me) took the opposite view, preferring the curly brace syntax. I suspect one's preference arrives from which languages you started coding in.

that particular block of code allows for opening the target file through the webserver or directly. the former way you would get the parsed code (i.e. just the html output) and the latter the whole shebang. you only get the latter if you put the override argument in place.
 
I changed this part:

Code:
else
    {
        [blue]$urlprefix="{$_SERVER['DOCUMENT_ROOT']}";[/blue]

Before $_SERVER it had double slashes, I removed them.

Ok got it, thanks!

-Kerry

 
think that was the old code. in my version of the code the double slashes were removed.
 
Kerry

since posting this I have been writing a lot of tutorials and needed a better system than CHIP. I came across the pear class called "Text_highlighter" ( it is much easier to use. by way of example

Code:
require_once "Text/Highlighter.php"; 
$disp =& Text_Highlighter::factory("HTML");
echo $disp->highlight (file_get_contents("somefile.html"));

it can handle different syntaxes or you can create your own. i have not been able to get it to sort out php within html (or vice versa) but i suspect that it should be able to do that with a bit of customisation.

you can do all the normal funny stuff like add numbers etc. you need a css file to use it. the css declarations that i use are as follows:

Code:
.hl-default {
    color: Black;
}
.hl-code {
    color: Gray;
}
.hl-brackets {
    color: Olive;
}
.hl-comment {
    color: Orange;
}
.hl-quotes {
    color: Darkred;
}
.hl-string {
    color: Red;
}
.hl-identifier {
    color: Blue;
}
.hl-builtin {
    color: Teal;
}
.hl-reserved {
    color: Green;
}
.hl-inlinedoc {
    color: Blue;
}
.hl-var {
    color: Darkblue;
}
.hl-url {
    color: Blue;
}
.hl-special {
    color: Navy;
}
.hl-number {
    color: Maroon;
}
.hl-inlinetags {
    color: Blue;
}
.hl-main { 
    background-color: White;
}
.hl-gutter {
    background-color: #999999;
    color: White
}
.hl-table {
    font-family: courier;
    font-size: 12px;
    border: solid 1px Lightgrey;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top