PHP explode()関数
例
文字列を配列に分割します。
<?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>
定義と使用法
explode()関数は、文字列を配列に分割します。
注:「separator」パラメーターを空の文字列にすることはできません。
注:この関数はバイナリセーフです。
構文
explode(separator,string,limit)
パラメータ値
Parameter | Description |
---|---|
separator | Required. Specifies where to break the string |
string | Required. The string to split |
limit | Optional. Specifies the number of array elements to return. Possible values:
|
技術的な詳細
戻り値: | 文字列の配列を返します |
---|---|
PHPバージョン: | 4歳以上 |
変更ログ: | PHP 4.0.1で制限パラメーターが追加され、PHP5.1.0で負の制限のサポートが追加されました。 |
その他の例
例
limitパラメーターを使用して、いくつかの配列要素を返します。
<?php
$str = 'one,two,three,four';
// zero limit
print_r(explode(',',$str,0));
// positive limit
print_r(explode(',',$str,2));
// negative limit
print_r(explode(',',$str,-1));
?>
❮PHP文字列リファレンス