Re: validating textarea using php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2008-05-13 at 19:02 +0300, Usamah al-Amin wrote:
> >  if(chop($comments) == "") { ... }   //hope that helps.
> 
> Well, chop() is an alias of rtrim(), so it won't work here for, say,
> trimming control characters at the end of the string like line feeds.
> 
> trim() is actually the best bit here.

Actually trim() is probably less efficient since both ends of the string
will be examined whereas a string containing entirely whitespace
characters will rtrim() (chop() if you will) to an empty string also but
the second side won't need to be examined (even if only to check for 0
length).

But maybe you didn't realize this because your assertion was wrong in
the first place:

> so it won't work here for, say, trimming control characters at the
> end of the string like line feeds.

When clearly looking at the online documentation for rtrim() we see:

    This function returns a string with whitespace stripped from
    the end of str . 

    Without the second parameter, rtrim() will strip these characters:

        " "    (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.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux