note 109852 added to function.trim
| From: | seyednaseratgmaildotcom | Date: | Tue, 28 Aug 2012 07:49:37 +0000 |
| Subject: | note 109852 added to function.trim | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190243@lists.php.net to get a copy of this message | ||
To show off the empty positions in a string by means of trim():
<?php
$string = " Hello World! ";
echo $string;
echo " Has : ".strlen($string)." letter(s). One by one according to the
following:<br />";
echo "<br />".$rightt = strlen(ltrim($string)) - strlen(trim($string))." empty
position(s) from right.";
echo "<br />".$leftt = strlen(rtrim($string)) - strlen(trim($string))." empty
position(s) from left.<br />";
$length = strlen($string);
for($x = 0; $x < $length; $x++){
$letter = substr($string, $x, 1);
if($letter <> " ")
echo "<br />Position $x ===>
".substr($string, $x, 1);
else
echo "<br />Position $x ===> Empty";
}
?>
the output is:
Hello World! Has : 19 letter(s). One by one according to the following:
3 empty position(s) from right.
4 empty position(s) from left.
Position 0 ===> Empty
Position 1 ===> Empty
Position 2 ===> Empty
Position 3 ===> Empty
Position 4 ===> H
Position 5 ===> e
Position 6 ===> l
Position 7 ===> l
Position 8 ===> o
Position 9 ===> Empty
Position 10 ===> W
Position 11 ===> o
Position 12 ===> r
Position 13 ===> l
Position 14 ===> d
Position 15 ===> !
Position 16 ===> Empty
Position 17 ===> Empty
Position 18 ===> Empty
----
Server IP: 130.185.72.20
Probable Submitter: 188.158.193.237
----
Manual Page -- http://www.php.net/manual/en/function.trim.php
Edit -- https://master.php.net/note/edit/109852
Del: integrated -- https://master.php.net/note/delete/109852/integrated
Del: useless -- https://master.php.net/note/delete/109852/useless
Del: bad code -- https://master.php.net/note/delete/109852/bad+code
Del: spam -- https://master.php.net/note/delete/109852/spam
Del: non-english -- https://master.php.net/note/delete/109852/non-english
Del: in docs -- https://master.php.net/note/delete/109852/in+docs
Del: other reasons-- https://master.php.net/note/delete/109852
Reject -- https://master.php.net/note/reject/109852
Search -- https://master.php.net/manage/user-notes.php