PHP

PHP Menu

PHP

trim() Function - Definition, Syntax, Parameters, Examples

Definition

The trim() function is used to remove whitespace and other predefined characters from both sides of a string.

Syntax

trim(string, charlist)

Parameters

Parameter Description
string Required. Specifies the string to check.
charlist Optional. 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

Example

<?php
$str = "Welcome to PHP!"; echo trim($str, "WP!");

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods