超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<highlight_fileignore_user_abort>
Last updated: Fri, 22 Jun 2007

highlight_string

(PHP 4 , PHP 5)

highlight_string -- Syntax highlighting of a string

Description

mixed highlight_string ( string str [, bool return])

The highlight_string() function outputs a syntax highlighted version of str using the colors defined in the built-in syntax highlighter for PHP.

If the second parameter return is set to TRUE then highlight_string() will return the highlighted code as a string instead of printing it out. If the second parameter is not set to TRUE then highlight_string() will return TRUE on success, FALSE on failure.

例子 1. highlight_string() example

<?php
highlight_string
('<?php phpinfo(); ?>');
?>

The above example will output (in PHP 4):

<code><font color="#000000">
<font color="#0000BB">&lt;?php phpinfo</font><font color="#007700">(); </font><font color="#0000BB">?&gt;</font>
</font>
</code>

The above example will output (in PHP 5):

<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php phpinfo</span><span style="color: #007700">(); </span><span style="color: #0000BB">?&gt;</span>
</span>
</code>

注: The return parameter became available in PHP 4.2.0. Before this time it behaved like the default, which is FALSE

See also highlight_file().




add a note add a note User Contributed Notes
highlight_string
marc at NOSPAM dot giombetti dot com
12-Jul-2003 08:17
There are already some functions for numbering and highliting a string containging PHP sourcecode on this site, but they were buggy or wasted recouces. I hope this snippet fits your needs.

 function my_highlight($text){  
      $text2 = stripslashes($text);
      $split = split("\n", $text2);  
      $mv = count($split);
 
  /*for design reasons */
  if($mv < 100){
  $width = "14";
  }elseif($mv < 1000){
  $width = "22";
  }elseif($mv < 10000){
  $width = "30";
  }else{
  $width = "14";
  }
 /*--------------------*/
      echo "<table bgcolor=\"#90ab83\" cellspacing=\"0\" width=\"100%\">";  

  $text2 = highlight_string($text2, true);  
      for($i = 0; $i < $mv; $i++){
          $t = $i + 1;  

          echo "<tr><td bgcolor=#7C9B6D width=$width><div align=right><font face=\"verdana\"
        size=\"1\">".$t."</font></div></td>";

          if($t < 2)  
          {  
  echo "<td style=\"padding-left: 5px\" rowspan=\"10000\" valign=\"top\">".$text2."</td>";  
        }

          echo "</tr>";    
      }
  echo"</table>";
  }

Yours Sincerely
Marc Giombetti - www.giombetti.com

<highlight_fileignore_user_abort>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22