Trim Function
Syntax:
trim(string,charlist)
The trim() function takes two parameters.
The trim() function strips whitespaces or other characters from the both sides i.e. beginning and end of a string.
If the second argument, charlist is not specified, trim() function strips all whitespace (" "), new line "\n", tab ("\t"), carriage return ("\r") by default.
trim(string,charlist)
The trim() function takes two parameters.
The trim() function strips whitespaces or other characters from the both sides i.e. beginning and end of a string.
If the second argument, charlist is not specified, trim() function strips all whitespace (" "), new line "\n", tab ("\t"), carriage return ("\r") by default.
Example: 1
<?php$str = ' This is a test. ';
$str_trimed = trim($str);
echo $str_trimed;
echo $str;
?>
Output
This is a test. This is a test.
Example: 2
<?php
$str = '?My workload is increasing. I am learning to prioritize.?';
$str_trimed = trim($str, "?");
echo $str;
echo "<br>";
echo $str_trimed;
?>
$str = '?My workload is increasing. I am learning to prioritize.?';
$str_trimed = trim($str, "?");
echo $str;
echo "<br>";
echo $str_trimed;
?>
Output
?My workload is increasing. I am learning to prioritize.?My workload is increasing. I am learning to prioritize.
Notice that '?' is trimmed both sides from string.
No comments:
Post a Comment