PHP常用語法1.PHP獲得字符串長度:
- $length = strlen($str);
PHP常用語法2.PHP判斷字符是否為NULL:
- if(!$str){
- echo "false"
- }else {
- echo "true"
- }
PHP常用語法3.link_to的使用:
- <?php echo link_to($question->getUser(),
'user/show?id='.$question->getUserId()) ?>
PHP常用語法4.PHP截取字符串:
- 1.split
- $arr = array();
- $arr = split("/",$str);<CODE><SPAN class=php_000000>
- </SPAN>
- </CODE>
PHP常用語法5. PHP替換字符串:
- 1. str_replace("-" , "/" , $str)
- "-" = 要替換的字符
- "/" = 替換後的字符
- 2.按數組方式替換:
- $arr = array("0","1","2","3","4","5","6","7","8","9");
- $repNum2 = str_replace($arr,"",$str);
PHP常用語法6.PHP獲取數組長度:
- $i=count($array_name);
PHP常用語法7. PHP獲得當前時間:
- $current_date = date("Ymd");
以上就是我們這次為大家總結的PHP常用語法。