PHP Funktion explode ()
Beispiele
String gebrochene Array:
<?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
?>
Ausführung einer Instanz »
Definition und Verwendung
explode () Funktion, um die String-Array aufzubrechen.
Hinweis: "Separator" Parameter nicht leer sein kann.
Hinweis: Diese Funktion ist binary safe ist.
Grammatik
explode( separator,string,limit )
参数 | 描述 |
---|---|
separator | 必需。规定在哪里分割字符串。 |
string | 必需。要分割的字符串。 |
limit | 可选。规定所返回的数组元素的数目。 可能的值:
|
Technische Details
Rückkehr: | Gibt ein Array von Strings. |
---|---|
PHP-Version: | 4+ |
Update-Protokoll: | In PHP 4.0.1, fügen Sie den Parameter Limit. In PHP 5.1.0, die neue Unterstützung für die negativen Grenzen. |
Weitere Beispiele
Beispiel 1
Verwenden Sie Parameter limit einige der Array-Elemente zurück:
<?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));
?>
$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));
?>
Ausführung einer Instanz »
PHP String Referenz