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 Chriss Miller 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
Joined
Dec 12, 2004
Messages
144
Location
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
 
I believe in you edit the php.ini file their should be a line for turning 'ON' html highlight.

imryn
 
how would I do this if I didn't have access to php.ini? is there a file I can use to override?

-Kerry
 
have a look at CHIP ( ).

you can see an example of this working on one of my sites:
the php syntax highlighter is all or nothing for html. there is no syntax sensitivity within html. however imryn is right that you can specify the colour for html highlight in php.ini. if you don't have access the following code snip should work
Code:
ini_set("highlight.html = #00FFFF");//or whatever colour you want
 
Ok cool, I'l look further into it.

I saw it before but it looked a bit complex, do you know if there are any tutorials regarding it? Or do I simply need to unzip the folders and do the same links you did?

I'm assuming you can customize the colors, line numbers, linespacing etc.?

Thank you very much,
Kerry
 
fully customisable. in fact i have to play with the code a bit to make it work as it used $_SERVER['argv'] and argc for stuff that it wasn't getting from my servers, and i also wanted to use url file references. post back if you want my mod'ed version.

basically you just call the chip.php file and provide it with some query parameters. at its most basic
Code:
header ("Location:chip.php?file=filename.html");

although i prefer to occlude chip and use readfile to keep the user within my own page.
 
Ok, I unzipped them all into my folder and tried just that line (except to index.html) and it gave me this:

file=index.html [] where is the name of the script to process; and can be any of file= where overrides any filename given earlier on the command line; dir= where specifies the directory where the CHIP CSS and JavaScript files are held (defaults to the empty string); title=); transition= where is a code for the page-entry transition, or -1 to disable transitions (defaults to 20); linenumbers= where is 0 to disable line numbers, or 1 to enable them (defaults to enabled); bcURL0= and bcTitle0=

Is this because of the same problem you had? ( I wouldn't mind using your version, there seems to be a lot of stuff. Do you know what file has the color management?)

Sincerely,
Kerry
 
yes. same problem. i'll post back with a url where to find the relevant file. i need to tidy my fix up a bit for public use.
 
download a fixed file from
this contains a fixed chip.php and chip-php.php. the latter needed fixing to capture shorttags (<?) as well as full php tags (<?php).

the former: i have cleaned up my fix to do least damage to the original code.
essentially:
1. unset $_SERVER['argc'] and ['argv']
2. change the $urlprefix such that it does not always default to an http file open (this will mean that the server will "serve" the file as parsed php rather than the source code). to get at the sourcecode I have added another query parameter called override. so to get the source of a file and display it inline:
Code:
readfile("chip.php?file=/path/to/file.php&linenumbers=1&override");

note, of course, that using the override parameter is a serious security risk. i would add some validation on incoming requests to make sure that they come from the localhost IP address.
 
Thank you!

I downloaded an replaced the files, but I have a feeling I'm still missing something. Is there some readme or documentation on what I need to have in my file? I simple have a test.php file that contains

Code:
<?
readfile("chip.php?file=index.html&linenumbers=1&override");
?>
<html>
<head>
</head>
<body>
</body>
</html>

and I have a feeling there is more to it than that. Also, on the security risk, is it because they could try to access any page with it?

Thank you very much,
Kerry
 
I looked more into your code and changed the page a bit, but it still doesn't work and I think its because I'm missing the behind-the-scenes php. Here's my current code:

Code:
<html>
<head>
<link rel="stylesheet" href="/chip/chip.css" title="CHIP"
      type="text/css" />
			<script type="text/javascript" src="/chip/rot13.js"></script>
<script type="text/javascript" src="/chip/chip.js"></script>
<script type="text/javascript">
<!--

chipFilePath = 'index.html';
chipPlainPageAnchorText = '(Load index.html without formatting)';
chipEmailLabelPrefix = 'chip-rotemailaddress';
chipTopLinkLabel = 'chip-toplink';
chipBottomLinkLabel = 'chip-bottomlink';

  function chipOnload()
  {

    chipFixRotEmails();
    chipFixLinks();
  }

// -->
</script>
</head>
<body onload="javascript:chipOnload()">
<?php echo pageHeader(); ?>                                
    <pre>                                                      
    <?php process(); ?>                                        
    </pre>                                                     
<?php echo pageFooter(); ?> 
</body>
</html>

Note, index.html is the file I'm trying to do right now, and its in the same directory as this file.

Thanks,
Kerry
 
even though it is in the same directory, you have to include the slash.

try (on the chip.php i put up for download)

Code:
readfile ("chip.php?file=/index.html&linenumbers=1&override");
 
It said: Warning: readfile("chip/chip.php?file=/index.html&linenumbers=1&override") - Invalid argument in c:\phpdev\ on line 7

Note, this is a personal apache server... should I try on another php one?

this is my code
Code:
<html>
<head>
<title>Page title</title>
</head>
<body>
<? 
readfile ("chip.php?file=/index.html&linenumbers=1&override");
 ?>


</body>
</html>

Sincerely,
Kerry
 
note sure what might be wrong. it won't be an apache thing.

note that as the file argument to the chip.php file you must give the path from the docroot, and NOT a relative path. it could be that it is failing for this reason although i also note that the error is reporting a different path to the code you have posted for the location of chip.php.

for the time being, why don't you try calling chip.php directly from the browser address bar. don't be put off by the http not found error if you have definitely typed in the address properly. the code sends this header when it can't find the file to highlight.
 
Yes, that works! Well, partially, if you give:

it works, but if I add the &override

Code:
[b]Warning:[/b] fopen("//c:/phpdev/[URL unfurl="true"]www//resume/index.html",[/URL] "rb") - No such file or directory in [b]c:\phpdev\www\resume\chip\chip.php[/b] on line [b]1523[/b]

[b]Warning:[/b] Cannot add header information - headers already sent by (output started at c:\phpdev\[URL unfurl="true"]www\resume\chip\chip.php:1523)[/URL] in [b]c:\phpdev\www\resume\chip\chip.php[/b] on line [b]1527[/b]
//c:/phpdev/[URL unfurl="true"]www//resume/index.html[/URL] not found

The other page still has the same error.

I think its a problem with readfile and permissions, but I'm not sure what it would be.

-Kerry
 
Oh, I forgot to note, readfile("chip/chip.php"); works, while readfile("chip/chip.php?file=/resume/index.html"); comes up with the invalid arg error.

-Kerry
 
my fault. the code is written for linux not windows. i'll post a variation later when i'm back at a pc. it's an easy fix.
 
Ok did that... I still have the same error.

I found that it doesn't like it the second I put a ? in it, is it possible that it's trying to read the file without loading it first?

Is there a way I can get a better error message?

This is my page's code

Code:
<?php 

$filepath = "chip/chip.php?file=/resume/index.html";
readfile($filepath);

//phpinfo();
 ?>

btw, php 4.2.3 apache 1.3.27

Thank you for all your help
 
could you try this:
Code:
$filepath = "[URL unfurl="true"]http://www.domain.com/path/to/chip/chip.php?file=/resume/index.html";[/URL]
readfile($filepath);

i.e. reference the chip.php as a url. that is how i always call the file. instead of doing it "inline" you can always, of course, use a
Code:
header("Location:$filepath");
to show a new page. but it does expose chip.php and with the override setting this could be a security hazard, allowing users to scoop passwords and file locations etc. this is why i prefer to use chip inline.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top