日历

« 2008-10-10  
   1234
567891011
12131415161718
19202122232425
262728293031 

统计信息

  • 访问量: 282
  • 日志数: 2
  • 建立时间: 2007-10-27
  • 更新时间: 2007-10-27

RSS订阅

我的最新日志

  • 从java程序员的角度看PHP(二)--关于调试

    2007-10-27

    jsp中,可以直接获得系统输出流和页面输出流,然后你可以随意的输出。
    <%
    System.out.print("这是系统输出流。");
    out.println("这是页面输出流。");
    %>

    在PHP中呢,只有页面输出流,好像还被称之为标准输出流。
    echo "这是页面输出流。";

    这一点无论怎么痛斥它都不为过。
    应对方案:

    在PHP中,定义公用函数,然后在每个页面中加载。在需要输出的地方使用debug($par);
    /**
     * 调试用到的全局变量,判断是否要把原来的内容清空
     */
    $debug_count = 0;

    /**
     * 向某个特定文件e:/debug.txt写信息
     *
     * @param string $content 要写入的信息
     */
    function debug($content)
    {
     global $debug_count;
     $debug_count++;
     if ($debug_count > 1) //已经有文件了
     {
      $file = fopen("e:/debug.txt","at");
     }
     else                //要建新文件
     {
      $file = fopen("e:/debug.txt","wt");
     }
     fwrite($file,('[' . date("H:i") . ']      ' . $content . "\n"));
     fclose($file);
    }
    UltraEdit编辑软件始终打开,并把“文件更改检测”设置为“自动更新已更改的文件(开)”,这样就可以在每次访问的中间查看变量,当然,如果再访问会刷新。

     

  • 乱码处理特别心得(2)--php相关

    2007-10-27

    主题:   乱码处理特别心得(2)--php相关


    需求:在url中传送有汉字参数,
    解决方法:
    (1)所有的PHP,js,css,html等文件都用utf-8编码。mysql建库时也用utf-8编码
    (2)php文件的开头使用
         header("Content-Type:text/html; charset=UTF-8");
    (3)用户提交表单的页面用js
       a.php
         <scrīpt>
           function commit() {
             var par = document.form1.name.value;
             window.location.href = 'b.php?name=' + encodeURI(par);
           }
         </scrīpt>
        
        
     <form name="form1">
    <input type="text" value="" name="name" />
    <input type="button" value="提交" ōnclick="commit()" />
    </form>
        
    (4)b.php
       echo $_GET['name']; //无需任何处理

Open Toolbar