strlen 


string apg

GET a STRING length.





This function return the length of the $string on SUCCESS and ZERO if the $string is EMPTY.



<?php

int strlen 
( str $string )


where,

$string = The string to determine the length

?>
 

$string


The STRING to get the length.



  1 EXERCISE   

<?php

$suprc 
= 'Supercalifragilisticexpialidocious';
$supnc = 'Anticonstitucionalissimamente';

$len_suprc = strlen($suprc);
$len_supnc = strlen($supnc);

echo 
$suprc . ' has ' . $len_suprc . ' characters<br><br>' . 
                   
$supnc  , ' has ' . $len_supnc . ' characters<br>';

?> 

 RESULT   

Supercalifragilisticexpialidocious
34 characters

Anticonstitucionalissimamente
29 characters


  2 EXERCISE   

<?php

$v02a 
= "abcdef";
$v02b = " ab de ";
$v02c = "";
$v02d = "\x90\x91\x00\x93\x94\x90\x91\x95\x96
                  \x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
;

echo 
"Testing strlen() : basic functionality:<br><br>";

echo 
$v02a . '<br>';
echo(
strlen($v02a));
echo 
' characters<br><br>';

echo 
$v02b . '<br>';
echo(
strlen($v02b));
echo 
' characters<br><br>';

echo 
$v02c . '<br>';
echo(
strlen($v02c));
echo 
' characters<br><br>';

echo 
$v02d . '<br>';
echo(
strlen($v02d));
echo 
' characters<br><br>';

?>

  3 EXERCISE   

<?php

/* In some ways, significantly 
   different from the previous exercise */

$v03a = 'abcdef';
$v03b = ' ab de ';
$v03c = '';
$v03d = '\x90\x91\x00\x93\x94\x90\x91\x95\x96
                  \x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f'
;

echo 
"Testing strlen() : basic functionality:<br><br>";

echo 
$v03a . '<br>';
echo(
strlen($v03a));
echo 
' characters<br><br>';

echo 
$v03b . '<br>';
echo(
strlen($v03b));
echo 
' characters<br><br>';

echo 
$v03c . '<br>';
echo(
strlen($v03c));
echo 
' characters<br><br>';

echo 
$v03d . '<br>';
echo(
strlen($v03d));
echo 
' characters<br><br>';

?>

  4 EXERCISE   

<?php

/* returns the length of a given string */

echo "Basic operations and  variations:<br><br>";
$strings = array( "Hello, World",
'Hello, World',
'!!Hello, World',
"??Hello, World",
"$@#%^&*!~,.:;?",
"123",
123,
"-1.2345",
-
1.2344,
NULL,
"",
" ",
"\0",
"\x000",                    // len = 2
"\xABC",                    // len = 2
"\0000",                    // len = 2
"0",
0,
"\t",                     // len = 1
'\t',                     // len = 2
TRUE,
FALSE,
"Hello, World\0",
"Hello\0World",
'Hello, World\0',
"Hello, World\n",
"Hello, World\r",
"Hello, World\t",
"Hello, World\\",
"              ",
chr(128).chr(234).chr(65).chr(255).chr(256),

"abcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_+=|?><-;:$
[]{}{{{}}}[[[[]][]]]***&&&^^%$###@@!!@#$%&^&**/////|\\\\\\
abcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_+=|?><-;:$
[]{}{{{}}}[[[[]][]]]***&&&^^%$###@@!!@#$%&^&**/////|\\\\\\
abcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_+=|?><-;:$
[]{}{{{}}}[[[[]][]]]***&&&^^%$###@@!!@#$%&^&**/////|\\\\\\
abcdefghijklmnopqrstuvwxyz0123456789"
);

/* loop through to find the length of each string */
for($i=0; $i<count($strings); $i++) {
echo 
"<br><br>String length of:<br> <b>'$strings[$i]'</b>
            <br> is => "
;
echo( 
strlen($strings[$i]) );
}

?>