初学,写一个函数用于存储日志调试。
<span style="color: #008080;"> 1</span> <span style="color: #0000ff;">function</span> WriteLog(<span style="color: #800080;">$msg</span><span style="color: #000000;">) </span><span style="color: #008080;"> 2</span> <span style="color: #000000;"> { </span><span style="color: #008080;"> 3</span> <span style="color: #800080;">$filename</span> = <span style="color: #008080;">dirname</span>(<span style="color: #ff00ff;">__FILE__</span>) ."\\Debug.log"<span style="color: #000000;">; </span><span style="color: #008080;"> 4</span> <span style="color: #800080;">$handler</span> = <span style="color: #0000ff;">null</span><span style="color: #000000;">; </span><span style="color: #008080;"> 5</span> <span style="color: #008080;"> 6</span> <span style="color: #0000ff;">if</span> ((<span style="color: #800080;">$handler</span> = <span style="color: #008080;">fopen</span>(<span style="color: #800080;">$filename</span>, 'ab+')) !== <span style="color: #0000ff;">false</span><span style="color: #000000;">) </span><span style="color: #008080;"> 7</span> <span style="color: #000000;"> { </span><span style="color: #008080;"> 8</span> <span style="color: #008080;">fwrite</span>(<span style="color: #800080;">$handler</span>, '['.<span style="color: #008080;">date</span>('Y-m-d H:i:s').']'."\t".<span style="color: #800080;">$msg</span>."\n"<span style="color: #000000;">); </span><span style="color: #008080;"> 9</span> <span style="color: #008080;">fclose</span>(<span style="color: #800080;">$handler</span><span style="color: #000000;">); </span><span style="color: #008080;">10</span> <span style="color: #000000;"> } </span><span style="color: #008080;">11</span> }