Re: note 28016 added to function.substr-count
| From: | Jesus M. Castagnetto | Date: | Mon, 30 Dec 2002 08:16:20 +0000 |
| Subject: | Re: note 28016 added to function.substr-count | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-41457@lists.php.net to get a copy of this message | ||
Your code is buggy, as it accepts incorrect addresses
like: 999.999.999.999
Your note will be removed.
--- webmaster@emugenerations.com wrote:
> This is a good example that claims how useful
> substr_count can be. This function checks if the
> given string is a IP address.
>
> function is_ip($str) // Returns True if the given
> string is a IP
> address
> {
> if ((substr_count($str, ".") != 3) or (empty($str)))
> { return false; }
>
> $ip_array = explode(".", $str);
>
> for ($i = 0; $i < count($ip_array); $i++)
> {
> if ((strlen($ip_array[$i]) != 3) or
> (!is_numeric($ip_array[$i])))
> {
> return false;
> }
> }
>
> return true;
> }
>
> If you like this function, please vote it:
> http://bugs.php.net/bug.php?id=21277
> --
>
http://www.php.net/manual/en/function.substr-count.php
>
http://master.php.net/manage/user-notes.php?action=edit+28016
>
http://master.php.net/manage/user-notes.php?action=delete+28016
>
http://master.php.net/manage/user-notes.php?action=reject+28016
>
>
> --
> PHP Notes Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
=====
--- Jesus M. Castagnetto <jmcastagnetto@php.net>
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com