PHP Programing language

trim() Functions in PHP
Previous Home Next
adplus-dvertising

trim()

This function removes the whitespaces from both start and the end of the string.

Syntax :
trim("string");

Example:

<?php
$str = "Gud Morning!";
echo $str . "<br>";
echo trim($str,"Gug!");
?>

Output:

Gud Morning!
d Mornin

ltrim()

This function removes the whitespaces from the left part of the string.

Syntax :
ltrim("string");

Example:

<?php
$str = "Gud Morning..!!!";
echo ltrim($str,"Gud");
?>

Output:

Morning..!!!

rtrim()

This function removes the whitespaces from the right part of the string.

Syntax :
rtrim("string");

Example:

<?php
$str = "Gud Morning";
echo rtrim($str,"Morning");
?>

Output:

Gud

Previous Home Next