PHP trim() Function

P
PHP substr_replace() Function
PHP ucfirst() Function

what is the syntax of the TRIM() function in php?

trim(string,charlist)
ParameterDescription
stringRequired. Specifies the string to check
charlistOptional. Specifies which characters to remove from the string. If omitted, all of the following characters are removed:”\0″ – NULL”\t” – tab”\n” – new line”\x0B” – vertical tab”\r” – carriage return” ” – ordinary white space
PHP TRIM() method

examples of the TRIM() function

Example 1. In this example, we remove characters from both sides of a string (“He” in “Hello” and “d!” in “World”).

<?php
$str = "Hello World!";
echo $str . "<br>";
echo trim($str,"Hed!");
?>

Example 2. In this example, we remove whitespaces from both sides of a string.

<?php
$str = " Hello World! ";
echo "Without trim: " . $str;
echo "<br>";
echo "With trim: " . trim($str);
?>

Example 3. In this example, we remove newlines (\n) from both sides of the string.

<?php
$str = "\n\n\nHello World!\n\n\n";
echo "Without trim: " . $str;
echo "<br>";
echo "With trim: " . trim($str);
?>
PHP substr_replace() Function
PHP ucfirst() Function

Add comment

Tutor Network

Share this

Learn PHP from A to Z