Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

eregi

(PHP 3, PHP 4, PHP 5)

eregi -- Case insensitive regular expression match

Description

int eregi ( string pattern, string string [, array &regs] )

This function is identical to ereg() except that this ignores case distinction when matching alphabetic characters.

Пример 1. eregi() example

<?php
$string
= 'XYZ';
if (
eregi('z', $string)) {
    echo
"'$string' contains a 'z' or 'Z'!";
}
?>

See also ereg(), ereg_replace(), eregi_replace(), stripos(), and stristr().



split> <eregi_replace
Last updated: Sat, 27 Jan 2007
 
add a note add a note User Contributed Notes
eregi
c00lways at gmail dot com
10-Mar-2007 06:10
hodsfords:

i love your expression,
and i've came out with a solutions which does not need to set the number of times {1,3} for the domain.
it can accept unlimited number of times, but @ least 1 time .com / .xxx

$exp = "^[a-z0-9]+[a-z0-9\?\.\+-_]*" .
@[a-z0-9_-]+(\.[a-z0-9_-]+)*\.[a-z]+$";
m at tthew dot org dot uk
07-Nov-2006 02:47
This example checks for a valid IP address or CIDR notation address range. (Thanks Walo for just the start I needed.)

The reg exp is too long to post in the code. It is:
^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(/[0-9]{1,2}){0,1}$
(substitute for EXPR)

<?php

function checkValidIp($cidr) {

   
// Checks for a valid IP address or optionally a cidr notation range
    // e.g. 1.2.3.4 or 1.2.3.0/24

  
if(!eregi("EXPR", $cidr)) {
      
$return = FALSE;
   } else {
      
$return = TRUE;
   }
   
    if (
$return == TRUE ) {

       
$parts = explode("/", $cidr);
       
$ip = $parts[0];
       
$netmask = $parts[1];
       
$octets = explode(".", $ip);

        foreach (
$octets AS $octet ) {
            if (
$octet > 255 ) {
               
$return = FALSE;
            }
        }

        if ( (
$netmask != "" ) && ( $netmask > 32 ) ) {
           
$return = FALSE;
        }

    }

    return
$return;

}

?>
Walo
02-Oct-2006 03:50
Simple function to check valid IP address

<?php
function checkValidIp($ip){
   if(!
eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $ip)) $return = FALSE;
   else
$return = TRUE;
    
  
$tmp = explode(".", $ip);
   if(
$return == TRUE){
      foreach(
$tmp AS $sub){
             
$sub = $sub * 1;
                if(
$sub<0 || $sub>256) $return = FALSE;
      }
   }
   return
$return;
}
?>
benjohnson{-at-}maine{-dot-}rr{-dot-}com
11-Sep-2006 02:33
It's probably worth noting that eregi() (and most likely, the related variations) appears to have a 255-character limit with respect to the length of the input it will attempt to parse.

If you try to do something like

if (!eregi("^[a-zA-Z0-9]{0,256}$", $text)) { ...

eregi() will return FALSE, irrespective of whether or not the input matches the pattern.
markus dot sipila at no dot spam dot iki dot fi dot invalid
02-Aug-2006 02:29
One more comment about email validation and usability of validators.

The fact that RFC 2822 allows broader set of characters in email addresses than typically used makes things quite challenging usability wise.

A very common usability problem with email validators is that they do not accept all valid addresses (such as foo{bar}.baz!@example.com. Almost as  common problem is that the validator only checks that the syntax is valid and passes addresses like foo#@example.com without any warning. Even though foo#@example.com is syntactically valid it might just as well be a typo of foo@example.com.

I resolved this usability challenge by doing the validation in two phases. In the first phase the address is validated so that it can't include exotic characters like { or |. Most addresses pass this validation.

If they don't, they are validated with the other validator that allows all RFC-compliant addresses. In this case the validator shows a message that the address is syntactically valid but it recommends to double check it for typos.

An example without regexps:
<?php
if (eregi($normal, $email)) {
  echo(
"The address $email is valid and looks normal.");
}

else if (
eregi($validButRare, $email)) {
  echo(
"The address $email looks a bit strange but it is syntactically valid. You might want to check it for typos.");
}

else {
  echo(
"The address $email is not valid.");
}
?>

The full article with the regexps and demo can be found at http://www.iki.fi/markus.sipila/pub/emailvalidator.php
tim at rocketry dot org
29-Apr-2006 09:32
The easiest way I've found to validate a properly formed email address is this:

if(!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", $_POST['EmailAddress'])) {
     echo "<p>Not a valid email address</p>\n";
}

It basically just wants to see some alphanumeric characters + an @ sign + a . + 2 to 4 alpha characters. So far it has done what I need for quite a while now.. Hope that helps someone. :)

Tim
info at stenschke dot com
03-Feb-2006 04:39
i needed a function to find hyperlinks containing a url as text of the hyperlink, exceeding a given maximum length.
here my function to finds too long hyperlinks and insert <br />s where needed into the linktext:

    function breakTooLongLinks($text,$maxLen) {
        //find hyperlinks that contain too many chars & insert <br>s where neccessary       
        $pattern= '[>]www[.].*/*(.doc|.pdf|.htm|.html|.shtml|.php|.asp)(</a>|</A>)';
        $match= eregi($pattern, $text, $regs);
        if ($match) {
            foreach ($regs as $link) {
                if (strlen($link)>$maxLen) {
                    $linkParts= explode('/',$link);
                    $linkRepl= array(); $replI=0; $curLinkPart='';
                    foreach($linkParts as $linkPart) {
                        $curLinkPart.= $linkPart.'/';
                        if (strlen($curLinkPart)>$maxLen) {
                            $linkRepl[]= $curLinkPart;
                            $curLinkPart='';
                        }
                    }
                    $linkRepl= implode('<br />',$linkRepl);                   
                    $text= str_replace($link, $linkRepl, $text);
                }
            }
        }
        return $text;
    }
opedroso at swoptimizer dot com
07-Jan-2006 05:13
I you are trying to match accented characters (e.g. you want to match "Caf
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571