标签:
第四节 PHP常用功能
1.字符串
<?php $str = ‘Hello Php‘; //获取字符所在的位置 echo strpos($str,‘o‘); //4 echo strpos($str,‘Ph‘); //6 //截取字符串 $str1= substr($str,2); echo $str1; //lo Php echo ‘<br>‘; //分割 $result = str_split($str,2); print_r($result); echo ‘<br>‘; //字符串分割 $str = "Hello PHP Java C# C++"; $result = explode(‘ ‘,$str); print_r($result); //字符串连接 $str2 = $str.‘<br>‘; $str2 = "$str<br>Object-c "; ?>
2 数组
<?php $arr = array(); $arr[0] = "Hello"; $arr[1] = "Word"; $arr[2] = 2; $arr[3] = 3.14; $arr[‘h‘] = "Hello"; $arr[‘w‘] = "Word"; $arr = array(‘h‘=>‘Hello‘, ‘w‘=>‘Word‘, ‘name‘=>‘Like‘); $arr = array(0=>‘Hello‘, 1=>‘Word‘,2=>‘Like‘); print_r($arr); for($i=0;$i<100;$i++) { array_push($arr,‘Item‘.$i); } print_r($arr); ?>
3 include与require
//依赖 每一次引用都会执行
require ‘lib.php‘// 只执行一次
require_once ‘lib.php‘//包含
include ‘lib.php‘;
标签:
原文地址:http://www.cnblogs.com/linksun/p/4468766.html