Entry
How do I split() a string at unquoted whitespace?
Dec 13th, 2002 01:14
Philip Olson, Del Rudolph,
The following:
<?php
$string = "Hello there friend bye!";
$arr = split('[ ]+', $string);
?>
Provides:
Array
(
[0] => Hello
[1] => there
[2] => friend
[3] => bye!
)
But if you did:
<?php
$string = "Hello there friend bye!";
$arr = explode(' ', $string);
?>
You'll get:
Array
(
[0] => Hello
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] => there
[9] => friend
[10] =>
[11] =>
[12] =>
[13] => bye!
)