** PLEASE DESCRIBE THIS IMAGE **
Logo Heather Nova Online Magazine

PHP Highlight - With a few lines of code you can have your own PHP Highlight script.





With a single line you can display, a syntax highlighted version of the given PHP code using the colors defined in the built-in syntax high lighter for PHP.

The "magic" happens when you use the highlight_string function in your PHP script.

How to use highlight_string?
<?php  echo highlight_string($code,true); ?>

That's simple enough, right? But how can you use it on your website?

The first thing we need is an HTML form where your visitor can enter his (or her) PHP code. This form needs to send the output to a PHP script that will highlight the code. 

Something like this:

--// source code: highlight.html //--
<form action="highlight.php" method="post" name="nice" target="_self" id="nice">
<table width="550" border="0" cellspacing="0" cellpadding="0">
<tr>
  <tr>
    <td><textarea name="code" cols="60" rows="25" style="text-wrap:normal;"></textarea></td>
  </tr>
  <tr>
    <td><input name="submit" type="submit"></td>
  </tr>
  </table>
</form>
--// source code: highlight.html //--

And then we'll need a script, named highlight.php:

--// source code: highlight.php //--
<table width="550" border="0" bgcolor="#E6E6E6">
  <tr>
    <td>
    <?php 
    
echo highlight_string($_POST['code'],true);
?>
</td>
  </tr>
</table>
--// source code: highlight.php //--

 

 

Written by Cynthia Fridsma



Rating for heathernova.us Heathernova.us is gold certified


Heather Nova Online Magazine 2012