Heim > Artikel > Backend-Entwicklung > PHP常用语法的总结笔记_PHP教程
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常用语法。