note 108069 deleted from function.str-split by danbrown

From: Date: Tue, 27 Mar 2012 15:34:41 +0000
Subject: note 108069 deleted from function.str-split by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-186852@lists.php.net to get a copy of this message
Note Submitter: Emilio ---- Hello! I don't know why when you try to split the string "&nbsp;", it doesn't work as usual. I was expecting the function to create an array like this: $arr = array( 0 => &, 1 => n, 2 => b, 3 => s, 4 => p); but it create an array with unknown characters. When I write printf("%x",$arrChr[$i]) or printf("%x",$chr), it display a 0. But if I do trim($word,"\0") obviously it do nothing. Why php treat this string as especial case? Sorry for bad English, here is the code. <?php $word = "&nbsp;"; $arrChr = str_split($word); for($i=0;$i<count($arrChr);$i++) printf($arrChr[$i]); foreach($arrChr as $chr) printf($chr); ?> I realise of this when I was trying to know if an input was empty. I saw it empty, but when I was doing trim($word)=="" was false and when I did strlen($word) it was 6! So I wanted to know if there were 6 null character or what. And when I did trim($word,$word[0]), it displayed "nbsp;". I hope this can be helpful for someone else. Greatings from bs as.

« previous php.notes (#186852) next »