<?Php
echo strlen('plus2net.com'); // Ouptut is 12
?>
Output is the length of the string in number of bytes.<?Php
$string="This is my string";
echo "Length of the string = ".strlen($string);
?>
The output of above code is 17
<?Php
$string="This is my string";
$string=str_replace(" ","",$string);
echo "Length of the string = ".strlen($string);
?>
The output of above code is 14
$string="abcdababcdababcs"; // Add or remove string chars to check output
if(strlen($string) >=6 and strlen($string) <=15)
{ echo "<br><br> length is wihtin 6 and 15 "; }
else { echo "<br><br> Not required length ";}
<?Php
$my_var1=null;
$my_var2='';
echo strlen($my_var1); // Ouptut is 0
echo strlen($my_var2); // Output is 0
?>
Checking null variable by using strlen() may not give desire result.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| elyn espanola | 05-02-2012 |
| what are the php codes of counting different letters from 2 words that given by the users and each word will be equal to the number of letters that are different to the other words. for example: cat=1 bratt=2 since in the word cat,there is no letter c in the other word so it equals to 1, then in the second word, there is no letter b and r in the first word so it equals to 2,tnx,,i need ur ideas. | |
| dickson | 07-12-2012 |
| nice stuff. home 4 the best. tank | |