Home > Article > Backend Development > Summary notes on common PHP syntax_PHP tutorial
PHP common syntax1.PHP gets the string length:
<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 common syntax 2. PHP determines whether a character is 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 common syntax 3. Use of 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>></span></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> </li></ol>
PHP commonly used Syntax 4. PHP intercepts string:
<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><SPAN class=tag-name>CODE</SPAN><SPAN class=tag>></span><span class="tag"><</SPAN><SPAN class=tag-name>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>></span></font></strong><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 commonly used Syntax 5. PHP replacement string:
<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 common syntax 6. PHP gets the array length:
<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 common syntax 7. PHP gets the current time:
<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>
The above is what we summarize for you this time Common PHP syntax.