PHP Tutorial : Clear white spaces

Ever got extra white spaces and dont wanna clear them manually or just cannot? In PHP, we have a great function called trim(), which will do your job. If you made a .htaccess rewrite (most of the cases), or just a form input to validate and clear its extra white spaces just do a trim().

<?php
$extraWhiteSpace = " bla bllla  b   l      a";
$extraWhiteSpace = trim($extraWhiteSpace);
?>
This entry was posted in Basic PHP and tagged , , , , , , , , . Bookmark the permalink.

2 Responses to PHP Tutorial : Clear white spaces

  1. Hitsh says:

    Hi! the function is not working.

    Its not printing any thing.

    will it remove the whitespaces or the string having illegal spaces?

    Thanks :)

  2. admin says:

    Of course it’s working but you need to add
    print $extraWhiteSpace;

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>