trim function in php

 Published April 23,2010 in PHP

Hello friend, welcome to my today's post on PHP. In my last tutorial, we learned about  "How to substr function works?". Hope you enjoyed that tutorial.

Today we are going to learn about "How trim function work in php?". So, Let's start -

One of the most important function to remove starting and ending space from a string. This function returns a string with whitespace stripped from the beginning and end of str. Without the second parameter, trim() will strip these characters.

Have a look examples-

  •   " " (ASCII 32 (0x20)), an ordinary space.
  • "\t" (ASCII 9 (0x09)), a tab.
  • "\n" (ASCII 10 (0x0A)), a new line (line feed).
  • "\r" (ASCII 13 (0x0D)), a carriage return.
  • "\0" (ASCII 0 (0x00)), the NUL-byte.
  • "\x0B" (ASCII 11 (0x0B)), a vertical tab.

how to use trim function in php

You can also specify the characters you want to strip, by means of the charlist parameter. Simply list all characters that you want to be stripped. You can  also specify a range of characters.

- How to write trim() Function:

string trim ( string str [, string charlist] )

- Write a live Example of trim() function:

Example 1. trim () example

how to use trim function in php

Demo & Source Code

- Important notes about trim() function:

The optional charlist parameter was added in PHP 4.1.0

Was this information useful? What other tips would you like to read about in the future?  Share your comments, feedback and experiences with us by commenting below!



Like our site? Be a member of Coolajax fan page to get daily posts updates!

recommended-tutorial You May Like This Posts!

» How to strcasecmp function works?

» PHP Introduction

» How to str function works?

» Classified Made Easy

» Best PHP Video Tutorials Part 2

  tuts_view Total Read: 637
blog comments powered by Disqus

Topics

Coolajax Fans

coolajax fan page on Facebook