note 32016 modified in function.strlen by thiago

From: Date: Wed, 11 Feb 2009 12:18:19 +0000
Subject: note 32016 modified in function.strlen by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-150478@lists.php.net to get a copy of this message
a little modification of rasmus solution <?php $tmp=0; $s="blah"; while($c=$s[$tmp++]) { echo $c; } ?> but what happens when the string contains zeros? <?php $s="blah0blah"; ?> the script stops.... here is sample of code and the string is correcly parsed using strlen() even when containing zeros: <?php $s="blah0blah"; $si=0; $s_len=strlen($s); for ($si=0;$si<$s_len;$si++) { $c=$s[$si]; echo $c; } ?> --was-- a little modification of rasmus solution $tmp=0; $s="blah"; while($c=$s[$tmp++]) { echo $c; } but what happens when the string contains zeros? $s="blah0blah"; the script stops.... here is sample of code and the string is correcly parsed using strlen() even when containing zeros: <? $s="blah0blah"; $si=0; $s_len=strlen($s); for ($si=0;$si<$s_len;$si++) { $c=$s[$si]; echo $c; } ?> http://php.net/manual/en/function.strlen.php

« previous php.notes (#150478) next »