note 17094 added to function.explode
| From: | louis dot brown at ukf dot net | Date: | Mon, 26 Nov 2001 10:58:36 +0000 |
| Subject: | note 17094 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-21277@lists.php.net to get a copy of this message | ||
If you intend to do the following
1. explode something
$array = explode("|", $string);
2. stick a value on to the end of the array
$array[] = "1234567890";
3. Then Implode it straight away.
$new_string = implode("|", $array);
Check that the original string ($string) has a value.
As exploding on an empty string and a string with one value
will both return 1.
If the string was empty the the new imploded string will look like this:-
"|1234567890"
Which is a pain when you come to explode it again as the first value in the array will be blank.
$string = "";
if ($string) != "")
{
$array = explode("|", $string);
}
else
{
$array = array();
}
$array[] = "1234567890";
$new_string = implode("|", $array);
--
http://www.php.net/manual/en/function.explode.php
http://master.php.net/manage/user-notes.php?action=edit+17094
http://master.php.net/manage/user-notes.php?action=delete+17094
http://master.php.net/manage/user-notes.php?action=reject+17094