FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » string length
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: string length [message #185322 is a reply to message #185320] Tue, 18 March 2014 15:53 Go to previous messageGo to previous message
Gabriel is currently offline  Gabriel
Messages: 11
Registered: March 2014
Karma:
Junior Member
On 18/03/2014 14:45, richard wrote:
> What can I use to count the number of characters in a string?
> strlen() does not seem to work properly.
> count_chars() does several different things but does not count the total.
> In BASIC I would use value=len(a$).
> I've had a look at the string functions and don't see a one that does this.
>
> what I'm looking to do is, read a directory and load an array based upon
> certain conditions of the file name.
>
> Using strlen and trying to match the file length to a fixed value does not
> work for me.
>
>
> $count=0;
> $yr=1959;
> while ($yr<=1969){
> if ($handle = opendir('audio/'.$yr)) {
> echo "Directory handle: $handle\n";
> echo "Entries:\n";
>
> /* This is the correct way to loop over the directory. */
> while (false !== ($entry = readdir($handle))) {
> $length=strlen($entry);
> if ($length==10){
> echo "$entry\n";
> echo "<br>";
> $count=$count+1;
> }
>
> }
>
> closedir($handle);
> }
> $yr++;
> }
>
> echo $count;
>

Keep in mind that strlen() does not technically count single printable
characters but rather bytes in a string. If the input to strlen() is a
multibyte encoded string (e.g. UTF8) then one character will actually be
counted as more than 1 by strlen().
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Nested PHP
Next Topic: weird global issue
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 19:38:23 GMT 2024

Total time taken to generate the page: 0.04123 seconds