note 4287 modified in explode by ronabop
| From: | ronabop@php.net | Date: | Fri, 11 Aug 2000 17:37:49 +0000 |
| Subject: | note 4287 modified in explode by ronabop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-1327@lists.php.net to get a copy of this message | ||
A question that has been asked several times by beginners: Please note, that if there is a
(white)space it ends up as the leading character of array element. There is big difference between
$item = "first string; 123"
and
$item = "first string;123"
To work properly you need to Trim() / LTrim() it away. However, pointing it out doesn't
provide just-add-water solution, so I add a snippet of ready-to-use code derived from the another
(non-working) snippet:
$itemlist = explode(";", $item);
//incorrect way
//$sql = "select * from <table> where <col>='$itemlist[0]' ";
//correct way
$sql = "select * from <table> where <col>='" . trim($itemlist[0]) .
"' ";
mysql_db_query=(<dbase>,$sql);
http://www.php.net/manual/function.explode.php