note 119212 added to function.explode

From: Date: Tue, 19 Apr 2016 19:44:44 +0000
Subject: note 119212 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-205283@lists.php.net to get a copy of this message
(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^ ---- Server IP: 72.52.91.14 Probable Submitter: 128.78.25.143 ---- Manual Page -- http://php.net/manual/en/function.explode.php Edit -- https://master.php.net/note/edit/119212 Del: integrated -- https://master.php.net/note/delete/119212/integrated Del: useless -- https://master.php.net/note/delete/119212/useless Del: bad code -- https://master.php.net/note/delete/119212/bad+code Del: spam -- https://master.php.net/note/delete/119212/spam Del: non-english -- https://master.php.net/note/delete/119212/non-english Del: in docs -- https://master.php.net/note/delete/119212/in+docs Del: other reasons-- https://master.php.net/note/delete/119212 Reject -- https://master.php.net/note/reject/119212 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205283) next »