标签:
字符串转数组
$str = ‘one|two|three|four‘;
print_r(explode(‘|‘, $str)); //explode 以字符串分割字符串到数组
$str = ‘one two three‘; //str_split 以位数分割 $arr1 = str_split($str); $arr2 = str_split($str, 3); print_r($arr1); print_r($arr2);
打印如下:
Array ( [0] => o [1] => n [2] => e [3] => [4] => t [5] => w [6] => o [7] => [8] => t [9] => h [10] => r [11] => e [12] => e ) Array ( [0] => one [1] => tw [2] => o t [3] => hre [4] => e )
数组转字符串
inplode()
字符串截取
substring 方法用于提取字符串中介于两个指定下标之间的字符
substring(start,end)
substr 方法用于返回一个从指定位置开始的指定长度的子字符串。
substr(start [, length ])
替换
str_replace()
把字符串 "Hello world!" 中的字符 "world" 替换为 "Shanghai":
echo str_replace("world","Shanghai","Hello world!");
preg_replace:执行一个正则表达式的搜索和替换
查找
preg_match();
preg_grep();
标签:
原文地址:http://www.cnblogs.com/isungge/p/4793974.html