note 4287 deleted from function.explode by jimw

From: Date: Fri, 07 Dec 2001 21:11:00 +0000
Subject: note 4287 deleted from function.explode by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-21990@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);

« previous php.notes (#21990) next »