note 119212 deleted from function.explode by salathe

From: Date: Mon, 21 Sep 2020 14:48:50 +0000
Subject: note 119212 deleted from function.explode by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215323@lists.php.net to get a copy of this message
Note Submitter: dark dot side01 at yahoo dot com ---- (excuse my english) When I try to use explode to know if a string contains many words, I noticed this : <?php $sentence= " word "; $array = explode($sentence); var_dump($array); ?> return this : array(4) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(4) "word" [3]=> string(0) "" } So, "explode" didn't keep the delimiter but counts it. You have to use trim($sentence) to count words in a sentence. ^v^

« previous php.notes (#215323) next »