PHP Coding Tips

Monday, August 13, 2012

How to remove white space in PHP (remove spaces at begining and end of string)?

You can remove trailing and leading white characters in PHP. What is white character ? it's just a character wich we don't see like tab, space, or new line character. To remove white space characters in PHP just use trim() function. It will do the work, here comes two sample codes:$trimmed = trim( $somestring ); echo "[".trim(" hello ")."]"; As you can see you can use this function inline to for example filter output.

No comments:

Post a Comment