PHP trim Function

What is trim Function?

Explanation

In PHP, this function is used strip whitespace or other characters from the beginning and end of a string.

Syntax:


trim(string,charlist)

In the above syntax given "string" is the input to strip characters, "charlist" specify the following characters to remove "","t","n","x0B","r"," ",if none is specified all the characters are removed.

Example :


<?php
$text
= "ttThese are a few words :) ... ";
echo "Without trim:".$text;
echo ">br/<";
echo "With trim:".trim($text);
?>
Result :

Without trim: These are a few words :) ...
With trim: These are a few words :) ...

In the above example the tab spaces,white spaces are removed from the string and displayed.

PHP Topics


Ask Questions

Ask Question