Syntax of trim() function and Usage.
trim(string,charlist)
Parameter Values
string -> Specifies the string to check.
charlist->Specifies which characters to remove.
If this is not mentioned then all of the following characters will be removed:
. “\0” – NULL
. “\t” – tab
. “\n” – new line
. “\x0B” – vertical tab
. “\r” – carriage return
. ” ” – ordinary white space
Let's learn
1.Create string
$str = "Hello World! welcome to BAJARANGISOFT";
2.Print string using trim() function.
echo trim($str,"HeT!");
Example(1)
<?php
$str = "Hello World! welcome to BAJARANGISOFT";
echo "<h4>$str </h4>";
echo trim($str,"HeT!");
?>
Complete Code of trim() Function:
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP trim function</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="text-center">
<h1>PHP trim() Function</h1>
</div>
<br>
<h2>The trim() function removes whitespace and other predefined characters from both sides of a string</h2>
<div class="well">
<?php
$str = "Hello World! welcome to BAJARANGISOFT";
echo "<h4>$str </h4>";
echo trim($str,"HeT!");
?>
</div>
<br>
</div>
</body>
</html>