$str = "abcdef"; print strlen($str);
6
$str = "a,b,c,d,e";
$ary = explode(",", $str);
print_r($ary);
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
)
$ary = array("a","b","c","d","e");
$str = implode(",", $ary);
print $str;
a,b,c,d,e
substr(文字列 , 開始位置 , 範囲)
開始位置は、正の場合は先頭から、負の場合は末尾からの位置です。
$str = "abcdef"; $result = substr($str,1,2); print $result;
bc
str_replace(検索 , 置換 , 対象)
$str = "abcdef";
$result = str_replace("b","x",$str);
print $result;
axcdef
$str = "abcdefabcdef"; $result = strpos($str,"bc"); print $result;
1
$str = "abcdefabcdef"; $result = strrpos($str,"b"); print $result;
7
最初に現れる場所から文字列の終わりまでを返します。
strstr は大文字小文字を区別します。stristr は大文字小文字を区別しません。
$str = "abcdefabcdef"; $result = strstr($str,"bc"); print $result;
bcdefabcdef