PHP,是英文超级文本预处理语言Hypertext Preprocessor的缩写。PHP 是一种 HTML 内嵌式的语言,是一种在服务器端执行的嵌入HTML文档的脚本语言,语言的风格有类似于C语言,被广泛的运用。本文总结了PHP日常开发中常用的8个小技巧。
1、命名
<ol class="dp-c"><li class="alt"><span><span><input><span class="string">'checkbox'</span><span> name=</span><span class="string">'checkbox[]'</span><span> value=</span><span class="vars">$dwmyrow</span><span>[banzhu] /> </span></span></span></li></ol>
2、使用
当计划当作sql指令的一部分时:如果参与控制的字段是数值型的,则
<ol class="dp-c"> <li class="alt"><span><span class="keyword">if</span><span>(! </span><span class="func">empty</span><span class="keyword">empty</span><span>(</span><span class="vars">$_POST</span><span>[</span><span class="string">'checkbox'</span><span>])) { </span></span></li> <li> <span class="vars">$expr</span><span> = join(</span><span class="string">","</span><span>, </span><span class="vars">$_POST</span><span>[</span><span class="string">'checkbox'</span><span>]); </span> </li> <li class="alt"> <span class="vars">$sql</span><span> = </span><span class="string">"select * from tbl_name where field in ($expr)"</span><span>; </span> </li> <li><span>} </span></li> </ol>
如果参与控制的字段是数值型的,则
<ol class="dp-c"> <li class="alt"><span><span class="keyword">if</span><span>(! </span><span class="func">empty</span><span class="keyword">empty</span><span>(</span><span class="vars">$_POST</span><span>[</span><span class="string">'checkbox'</span><span>])) { </span></span></li> <li> <span class="vars">$expr</span><span> = </span><span class="string">"'"</span><span>.join(</span><span class="string">"','"</span><span>, </span><span class="vars">$_POST</span><span>['checkbox']).</span><span class="string">"."</span><span>; </span> </li> <li class="alt"> <span class="vars">$sql</span><span> = </span><span class="string">"select * from tbl_name where field in ($expr)"</span><span>; </span> </li> <li><span>} </span></li> </ol>
PHP判断Form表单是否提交
<ol class="dp-c"> <li class="alt"><span><span class="vars">$action</span><span>=</span><span class="vars">$HTTP_POST_VARS</span><span>[</span><span class="string">"Button1"</span><span>]; </span></span></li> <li> <span class="keyword">if</span><span>(</span><span class="vars">$action</span><span>==</span><span class="string">"提交"</span><span>) </span> </li> <li class="alt"><span>{ </span></li> <li> <span class="comment">//执行表单操作 </span><span> </span> </li> <li class="alt"><span>} </span></li> <li> <span class="keyword">else</span><span> </span> </li> <li class="alt"><span>{ </span></li> <li> <span class="comment">//读取默认值 </span><span> </span> </li> <li class="alt"><span>} </span></li> </ol>
PHP 获取字符串长度
<ol class="dp-c"><li class="alt"><span><span class="func">strlen</span><span>(</span><span class="vars">$myrow</span><span>[1]) </span></span></li></ol>
PHP Url转向
<ol class="dp-c"><li class="alt"><span><span>Header(</span><span class="string">"Location: "</span><span>.</span><span class="vars">$_SERVER</span><span>[</span><span class="string">"HTTP_REFERER"</span><span>]); </span></span></li></ol>
PHP超全局对象
<ol class="dp-c"> <li class="alt"><span><span><?php </span></span></span></li> <li> <span class="vars">$a</span><span> = 1; </span> </li> <li class="alt"> <span class="vars">$b</span><span> = 2; </span> </li> <li> <span class="keyword">function</span><span> Sum() </span> </li> <li class="alt"><span>{ </span></li> <li> <span class="vars">$GLOBALS</span><span>[</span><span class="string">"b"</span><span>] = </span><span class="vars">$GLOBALS</span><span>[</span><span class="string">"a"</span><span>] + </span><span class="vars">$GLOBALS</span><span>[</span><span class="string">"b"</span><span>]; </span> </li> <li class="alt"><span>} </span></li> <li><span>Sum(); </span></li> <li class="alt"> <span class="func">echo</span><span> </span><span class="vars">$b</span><span>; </span> </li> <li><span>?> </span></li> </ol>
PHP 表单取值
如果 mothod="get" 就用 $_GET["test"] 代替$test
如果 mothod="post" 就用 $_POST["test"] 代替$test
PHP取得当前IP
<ol class="dp-c"> <li class="alt"><span><span>=</span><span class="vars">$HTTP_SERVER_VARS</span><span>[</span><span class="string">"REMOTE_ADDR"</span><span>]?> </span></span></li> <li><span>PHP 取得当前时间 </span></li> <li class="alt"><span> </span></li> <li><span><?php </span></span></li> <li class="alt"> <span class="func">echo</span><span> </span><span class="func">date</span><span>(</span><span class="string">"Y-m-d G:i:s"</span><span>); </span> </li> <li><span>?> </span></li> <li class="alt"> <span class="func">date</span><span>(</span><span class="string">"Y年m月d日"</span><span>) </span> </li> <li> <span class="func">Date</span><span> (</span><span class="string">"Y-n-j"</span><span>) </span> </li> </ol>
希望通过本文的介绍,能给你带来帮助。
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章
刺客信條陰影:貝殼謎語解決方案
3 週前ByDDD
Windows 11 KB5054979中的新功能以及如何解決更新問題
3 週前ByDDD
在哪裡可以找到原子中的起重機控制鑰匙卡
3 週前ByDDD
<🎜>:死鐵路 - 如何完成所有挑戰
4 週前ByDDD
Atomfall指南:項目位置,任務指南和技巧
1 個月前ByDDD

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

Atom編輯器mac版下載
最受歡迎的的開源編輯器

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

禪工作室 13.0.1
強大的PHP整合開發環境

WebStorm Mac版
好用的JavaScript開發工具