Forums »
  PHP Forums And Topics Discussions About Hyper Text Programming Language »
    PHP Learn How To Count Characters Letters Are In A String Script Function

PHP Learn How To Count Characters Letters Are In A String Script Function

Description: PHP Learn How To Count Characters Letters Are In A String Script Function
Tags: php ,learn ,how ,to ,count ,characters ,letters ,are ,in ,a ,string ,script ,function
Posted On Sat Feb 03, 2007 By hostman In PHP Forums And Topics Discussions About Hyper Text Programming Language Forums
the other day i wanted to limit the amount of characters in a form, instead of relying on the user, i found out how to do this with php. php has a fucntion called strlen($string) that gives you the amount of characters in a string, the string can be letter or numbers in a sentence or paragraph.

so if you want to write a script to check the number of characters a user to your web site has submitted, you can do this with php with the strlen($string); function. with this function you can tell how many characters you have in a string.

the following code will output 12

CODE:
$string="wallpaperama";

$num_char=strlen($string);

echo $num_char;


hope this helps, if you have any other tips, let me know write you comments or reply to this post. thanks.
Web Fri May 20, 2011
Just what I needed for my current project :-) thanks!!
Bjarne Tue Dec 21, 2010
mb_strlen counts and swedish.
ert Sun Jul 04, 2010
04-778-contbtmbdr.gif
PHP Learn How To Count Characters Letters Are In A String Script Function
ArMaNd0 Tue Dec 15, 2009
thank you sir, i am from the country of El Salvador - I am a web developer who writes programs for websites, and this function will come in very handy

Regards
abe Mon Dec 07, 2009
thanx, terimakasih
Atle Sat Oct 31, 2009
just wanted to say thanks for this small "guide" :)
Priyanka Tue Jun 30, 2009
is there any php function to count number of spaces in a string?
Mats Sat Jun 06, 2009
strlen on its own doesn't work with multibyte characters, like the swedish letters å, ä and ö. you have to use utf8_decode. sample code:
$string = 'våren är grön!'; //spring is green!
$char1 = strlen($string);
echo $char1; //17 = not correct!
$char2 = strlen(utf8_decode($string));
echo $char2; //14 = correct!
aditya Sat May 23, 2009
at umar : just, fyi, space is also a character, so if you wont to count the alphabet only, use explode with space character, and count one by one .. :) sorry dude, maybe not help.. :)
Umar Wed Jan 14, 2009
it is not correct in case
$string = "it is about 2900 and 500.";

now can you count only alphabets from this string.
i am waiting for reply. my email is umar.jaan at google
Adaptiv Sun Dec 07, 2008
thanks for this. i'm looking to show just the first few sentences of a news item as a teaser in my up and coming news management system. hopefully i'm thinking i can somehow develop this to pick the first 100 characters out and then trim the last word off if it is cut short.
hagar Sat Aug 09, 2008
you can hack my me, my ip address is: 84.36.151.185
my email is: baby_lover_girl2007@yahoo.com
ayush Thu May 22, 2008
thanks i am very happy thatks very much
Fabulous Thu Feb 14, 2008
php is soooo powerful ! i'm definitely glad to have switched to this language.

truly impressive
Information
Title: PHP Learn How To Count Characters Letters Are In A String Script Function
Info: This Post Has Been Viewed 0 Times Since
Date: Sat Feb 03, 2007
Author hostman Received 14 Replies #1004
Related Content
Related Pages
Related Sites
Add Your Website
Share
wallpaperama | Wallpapers | Forums | Terms Of Service

copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Tue Jun 18, 2013 (-8 GMT)
Powered by: Webune Forums V5