PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
nigma
DevNet Resident
Posts: 1094 Joined: Sat Jan 25, 2003 1:49 am
Post
by nigma » Tue Oct 28, 2003 6:40 pm
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.
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Tue Oct 28, 2003 6:42 pm
Code: Select all
<?php
$str = 'abcdef';
echo strlen($str); // 6
$str = ' ab cd ';
echo strlen($str); // 7
?>
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Tue Oct 28, 2003 6:44 pm
btw,
letters + symbols + numbers = characters
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Tue Oct 28, 2003 6:47 pm
Code: Select all
<?php
$str = 'abcdef';
echo strlen(str_replace(' ','',$str)); // 6
$str = ' ab cd ';
echo strlen(str_replace(' ','',$str)); // 4
?>
nigma
DevNet Resident
Posts: 1094 Joined: Sat Jan 25, 2003 1:49 am
Post
by nigma » Tue Oct 28, 2003 6:48 pm
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().