高亮你的PHP代码

类别:编程语言 点击:0 评论:0 推荐:

PHP有一个很有用但是很多人都没有注意到的函数:highlight_string使用它你可以很轻松的高亮你的PHP代码。不过要注意,highlight_string返回一个Boolean值,它会直接把生成的HTML代码显示出来。下面是我写的一个简单的PHP脚本,你可以通过它来高亮你的代码,然后通过在线编辑器贴到CSDN上边:) 建议粘贴之后把字体设为 Courier New 这样看起来更方便

 

如果你比较懒,也可以访问http://exlcsoft.com/es5/highlight.php 来高亮你的代码~

 

  

<?php

error_reporting(E_ALL & ~E_NOTICE);
@extract($HTTP_SERVER_VARS, EXTR_SKIP);
@extract($HTTP_COOKIE_VARS, EXTR_SKIP);
@extract($HTTP_POST_FILES, EXTR_SKIP);
@extract($HTTP_POST_VARS, EXTR_SKIP);
@extract($HTTP_GET_VARS, EXTR_SKIP);
@extract($HTTP_ENV_VARS, EXTR_SKIP);

if ( $step != 2 )
{
    echo '<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>php highlighter</title>
<style>
<!--
input        { border: 1px solid #000000;font-family: Courier New; font-size: 9pt }
textarea     { border: 1px solid #000000;font-family: Courier New; font-size: 9pt }
body         { scrollbar-face-color:white; scrollbar-shadow-color:black;
scrollbar-highlight-color:black; scrollbar-3dlight-color:white;
scrollbar-darkshadow-color:white; scrollbar-track-color:#f9f9f9;
scrollbar-arrow-color:black;font-family: Courier New; font-size: 9pt}
-->
</style>
</head>

<body>
PHP CODE highlight <br>
-------------------- <br>
@ [email protected] <br>
@ 2003 06 <p>
Please input the code: <br>
<form method="POST" >
  <textarea rows="15" name="con" cols="44"></textarea></p>
  <p><INPUT TYPE="hidden" name="step" value="2"><input type="submit" value="提交" name="B1"></p>
</form>

</body>
</html>';

}
else
{
    echo '<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>php highlighter</title>
<style>
<!--
a            { color: #FF0000; text-decoration: none }
font            {  text-decoration: none;font-family: Courier New; font-size: 9pt }
input        { border: 1px solid #000000 }
textarea     { border: 1px solid #000000 }
body         { scrollbar-face-color:white; scrollbar-shadow-color:black;
scrollbar-highlight-color:black; scrollbar-3dlight-color:white;
scrollbar-darkshadow-color:white; scrollbar-track-color:#f9f9f9;
scrollbar-arrow-color:black;font-family: Courier New; font-size: 9pt}
-->
</style>
</head>

<body>';
    highlight_string ( stripslashes($con) ) ;
echo '<p><a href="?">click here to go back...</a></body></html>';
    
}




?>

本文地址:http://com.8s8s.com/it/it29237.htm