PHP常用语法的总结笔记_PHP教程

WBOY
發布: 2016-07-15 13:29:40
原創
763 人瀏覽過

PHP常用语法1.PHP获得字符串长度:

<ol class="dp-xml"><li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">length</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">strlen</font></span><span>($str);   </span></span></li></ol>
登入後複製

PHP常用语法2.PHP判断字符是否为NULL:

<ol class="dp-xml">
<li class="alt"><span><span>if(!$str){     </span></span></li>
<li class=""><span>   echo "false"    </span></li>
<li class="alt"><span>    </span></li>
<li class=""><span>}else {     </span></li>
<li class="alt"><span>   echo "true"    </span></li>
<li class=""><span>    </span></li>
<li class="alt"><span>}    </span></li>
</ol>
登入後複製

PHP常用语法3.link_to的使用:

<ol class="dp-xml"><li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> echo link_to($question-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getUser(), <br>'user/show?</span><span class="attribute"><font color="#ff0000">id</font></span><span>='.$question-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getUserId()) </span><span class="tag"><strong><font color="#006699">?></font></strong></span><span>  </span></span></li></ol>
登入後複製

PHP常用语法4.PHP截取字符串:

<ol class="dp-xml">
<li class="alt"><span><span>1.split     </span></span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">arr</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">array</font></span><span>();     </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">arr</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">split</font></span><span>("/",$str);</span><strong><font color="#006699"><span class="tag"><span class="tag-name">CODE</span><span class="tag">></span><span class="tag"><span class="tag-name">SPAN</span></span></span></font></strong><span> </span><span class="attribute"><font color="#ff0000">class</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">php_000000</font></span><span class="tag"><strong><font color="#006699">></font></strong></span><span>     </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">SPAN</span><span class="tag">></span></font></strong><span>     </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">CODE</span><span class="tag">></span></font></strong><span>    </span>
</li>
</ol>
登入後複製

PHP常用语法5. PHP替换字符串:

<ol class="dp-xml">
<li class="alt"><span><span>1. str_replace("-" , "/" , $str)     </span></span></li>
<li class=""><span>"-" = 要替换的字符     </span></li>
<li class="alt"><span>"/" = 替换后的字符     </span></li>
<li class=""><span>    </span></li>
<li class="alt"><span>2.按数组方式替换:     </span></li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">arr</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">array</font></span><span>("0","1","2","3","4","5","6","7","8","9");     </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">repNum2</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">str_replace</font></span><span>($arr,"",$str);  </span>
</li>
</ol>
登入後複製

PHP常用语法6.PHP获取数组长度:

<ol class="dp-xml"><li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">i</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">count</font></span><span>($array_name);   </span></span></li></ol>
登入後複製

PHP常用语法7. PHP获得当前时间:

<ol class="dp-xml"><li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">current_date</font></span><span> = date("Ymd");   </span></span></li></ol>
登入後複製

以上就是我们这次为大家总结的PHP常用语法。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446352.htmlTechArticlePHP常用语法 1.PHP获得字符串长度: $ length = strlen ($str); PHP常用语法2.PHP判断字符是否为NULL: if(!$str){ echo"false" }else{ echo"true" } PHP常用语法3.l...
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板