note 108069 added to function.str-split
| From: | Emilio | Date: | Mon, 26 Mar 2012 19:34:01 +0000 |
| Subject: | note 108069 added to function.str-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186826@lists.php.net to get a copy of this message | ||
Hello! I don't know why when you try to split the string " ", 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 = " ";
$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.
----
Server IP: 190.2.55.64
Probable Submitter: 190.2.21.21 (proxied: 168.83.81.41)
----
Manual Page -- http://www.php.net/manual/en/function.str-split.php
Edit -- https://master.php.net/note/edit/108069
Del: integrated -- https://master.php.net/note/delete/108069/integrated
Del: useless -- https://master.php.net/note/delete/108069/useless
Del: bad code -- https://master.php.net/note/delete/108069/bad+code
Del: spam -- https://master.php.net/note/delete/108069/spam
Del: non-english -- https://master.php.net/note/delete/108069/non-english
Del: in docs -- https://master.php.net/note/delete/108069/in+docs
Del: other reasons-- https://master.php.net/note/delete/108069
Reject -- https://master.php.net/note/reject/108069
Search -- https://master.php.net/manage/user-notes.php