Home | Scripts | Tutorials | Books | Hosting | Forums | Links|

Navigation:

Home
Source code
Tutorials
RSS feeds
Articles
Books
Software
Downloads
Hosting
manuals
Forums
Script directory
Training
Our Links

ADD TO Progged Progged
ADD TO DEL.ICIO.US Del.icio.
ADD TO DIGG Digg
ADD TO FURL Furl
ADD TO NEWSVINE Newsvine
ADD TO NETSCAPE Netscape
ADD TO REDDIT Reddit
ADD TO STUMBLEUPON StumbleUpon
ADD TO TECHNORATI FAVORITES Technorati
ADD TO SQUIDOO Squidoo
ADD TO WINDOWS LIVE Windows Live
ADD TO YAHOO MYWEB Yahoo MyWeb
ADD TO ASK Ask
ADD TO GOOGLE Google
ADD TO MAGNOLIA Magnolia
ADD TO SPURL Spurl



 
 

SPONSORS



 
 

Getting the length of a string

This example shows how you can get the length of a string , this uses the function strlen() . The format of strlen is strlen(string); . This returns the length of a string as an integer .

In the example below we have 2 strings , the reason behind this is to show that when we measure the length of a string we also measure all of the string not only the characters but the whitespace also.

Code :

<?php
//display length of string(s)
$string1 = "beginners php";
$string2 = "myscripting";
//store the length of the strings in variables
$length1 = strlen($string1);
$length2 = strlen($string2);
//display the length of the strings
echo "String1 has $length1 characters";
echo "String2 has $length2 characters";
?>

Example :

string1 has 13 characters
string2 has 11 characters