T、文字列の長さを調べる
$msg = "ABCDEFG";
$len = strlen($msg);
$len=7となる
U、文字列をトークンに分解する
※サンプルT
$msg = "2016/10/06";
$year = strtok($msg, "/"); // $year = 2016
$month = strtok("/"); // $month = 10
$day = strtok("/"); // $day = 6
※サンプルU
$msg = "2016/10/06";
$idx = 0;
$tokn[idx] = strtok($msg, "/");
while(($wtokn = strtok("/")) !== false) {
$tokn[idx] = $wtokn;
$idx++;
}
V、部分文字列を取得する
※先頭の文字の位置は「0」
$msg = "ABCDEFGHIJKLMN";
$sel = substr($msg, 2, 5); // 3番目の文字列から5桁の文字列
$sel = substr($msg, 9); // 10番目の文字列から末尾までの文字列
W、文字列を指定した文字列で分割する
$msg = "太郎/花子/次郎";
$spl = explode("/",$msg);
実行結果
$spl[0] = "太郎"
$spl[1] = "花子"
$spl[2] = "次郎"
|