Why we use PHP String functions trim(), ltrim() and rtrim()?

PHP trim related functions are used to remove white spaces or other given characters from the beginning and end of the strings.

  • trim() removes space & predefined characters from both sides of given string.
  • ltrim() removes space & predefined characters from the left side of the sting.
  • rtrim() removes space & predefined characters from the right side of the sting.

These functions are helpful when we want to clean strings from unwanted spaces or characters.

Syntax: trim(string,charlist)

Example:

$sample_string = '  Welcome to TutorialsClass.com ';
$clean_string = trim($sample_string);

Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.