- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
trim() function in PHP
The trim() function is used to remove whitespaces and other characters.
Syntax
trim(str, charlist):
Parameters
str − Specify the string to check.
charlist − Specifies which characters to remove. If this parameter isn’t used, then any of the following characters are removed −
"\0" - NULL
"\t" - tab
"
" - new line"\x0B" - vertical tab
"\r" - carriage return
Return
The trim() function returns the modified string.
Example
The following is an example −
<?php $str = "
Demo text!
"; echo "Trim: " . trim($str); ?>
Output
The following is the output −
Trim: Demo text!
Example
Let us see another example −
<?php $mystr = "Demo text!"; echo trim($mystr, "Dam!"); ?>
Output
The following is the output −
emo text
Advertisements