<span style="margin: 0px; color: #000088; vertical-align: baseline; border-width: 0px; padding: 0px;" class="kwd">function</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln"> aa</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">(</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">$str</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">)</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln"> </span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">{</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln"> echo $str</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">;</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln"></span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">}</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">$function </span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">=</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln"> </span><span style="margin: 0px; color: #008800; vertical-align: baseline; border-width: 0px; padding: 0px;" class="str">"aa"</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">;</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">$function</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">(</span><span style="margin: 0px; color: #008800; vertical-align: baseline; border-width: 0px; padding: 0px;" class="str">'Hello'</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">);</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln"></span><span style="margin: 0px; color: #880000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="com">// OR</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">call_user_func</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">(</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">$function</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">,</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln"> $param</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">);</span>
登入後複製
2. 列出所有函数,判断某个函数是否存在
<span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">get_defined_functions</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">()</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">function_exist</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">()</span>
登入後複製
3. 接受 PUT 请求,PHP REST 必备
<span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">parse_str</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">(</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">file_get_contents</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">(</span><span style="margin: 0px; color: #008800; vertical-align: baseline; border-width: 0px; padding: 0px;" class="str">'php://input'</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">),</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln"> $put_vars</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">);</span>
登入後複製
4. 从字符串解析时间
<span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">echo date</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">(</span><span style="margin: 0px; color: #008800; vertical-align: baseline; border-width: 0px; padding: 0px;" class="str">'Y-m-d'</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">,</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln"> strtotime</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">(</span><span style="margin: 0px; color: #008800; vertical-align: baseline; border-width: 0px; padding: 0px;" class="str">'-1 month ago'</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">));</span>
登入後複製
5. DEBUG 查看调用 backtrace
<span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">$backtrace </span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">=</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln"> debug_backtrace</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">();</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">var_export</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">(</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">$backtrace</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">[</span><span style="margin: 0px; color: #006666; vertical-align: baseline; border-width: 0px; padding: 0px;" class="lit">0</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">])</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln"></span><span style="margin: 0px; color: #000088; vertical-align: baseline; border-width: 0px; padding: 0px;" class="kwd">die</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">();</span>
登入後複製
6. 交互式命令行,命令行执行 PHP
php -a 和 php -r ‘echo “hello”;’
更多请看 php -h
7. 内存使用检测
<span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">memory_get_peak_usage</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">()</span><span style="margin: 0px; color: #000000; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pln">memory_get_usage</span><span style="margin: 0px; color: #666600; vertical-align: baseline; border-width: 0px; padding: 0px;" class="pun">()</span>
登入後複製