Page 1 of 1
Counting letters in string
Posted: Tue Oct 28, 2003 6:40 pm
by nigma
Hey, would anyone be willing to give me a function that can be used to count the number of (letters | numbers | symbols) in a string?
thanks for all help provided.
Posted: Tue Oct 28, 2003 6:42 pm
by d3ad1ysp0rk
Code: Select all
<?php
$str = 'abcdef';
echo strlen($str); // 6
$str = ' ab cd ';
echo strlen($str); // 7
?>
Posted: Tue Oct 28, 2003 6:44 pm
by d3ad1ysp0rk
btw,
letters + symbols + numbers = characters
Posted: Tue Oct 28, 2003 6:47 pm
by JAM
Code: Select all
<?php
$str = 'abcdef';
echo strlen(str_replace(' ','',$str)); // 6
$str = ' ab cd ';
echo strlen(str_replace(' ','',$str)); // 4
?>
Posted: Tue Oct 28, 2003 6:48 pm
by nigma
Thanks guys, I was just getting ready to delete post when I saw your replies. I ended up using strlen(), but also looked at count_chars().