1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Please Help Correcting PHP Code, Eregi Function

Discussion in 'PHP' started by WebDevNow, Apr 25, 2012.

  1. #1
    Hello,
    I got some problems for eregi function,
    Please Help me Correcting the Following Code, and tell me how should it be to work properly,

    
    [COLOR=#999988][I]// check the domain validity:[/I][/COLOR]
            [B]if[/B]([B]![/B][COLOR=#0086B3]eregi[/COLOR]([COLOR=#DD1144]'^[a-zA-Z0-9\-]{1,}$'[/COLOR], [COLOR=#008080]$domain[/COLOR]))  [B]return[/B] [B]false[/B];
            [B]if[/B]([COLOR=#0086B3]eregi[/COLOR]([COLOR=#DD1144]'[-]{2,}'[/COLOR], [COLOR=#008080]$domain[/COLOR]))               [B]return[/B] [B]false[/B];
            [B]if[/B]([COLOR=#0086B3]eregi[/COLOR]([COLOR=#DD1144]'^[-]{1,}'[/COLOR], [COLOR=#008080]$domain[/COLOR]))              [B]return[/B] [B]false[/B];
            [B]if[/B]([COLOR=#0086B3]eregi[/COLOR]([COLOR=#DD1144]'[-]{1,}$'[/COLOR], [COLOR=#008080]$domain[/COLOR]))              [B]return[/B] [B]false[/B];
    
    
    
    
    		[COLOR=#008080]$data[/COLOR] [B]=[/B] [COLOR=#008080]$this[/COLOR][B]->[/B][COLOR=#008080]whois[/COLOR]([COLOR=#008080]$tld_array[/COLOR][[COLOR=#DD1144]"whois_server"[/COLOR]],[COLOR=#008080]$domain[/COLOR] [B].[/B] [COLOR=#DD1144]'.'[/COLOR] [B].[/B] [COLOR=#008080]$tld[/COLOR]);
    		[B]if[/B]([B]![/B][COLOR=#008080]$data[/COLOR]) [B]return[/B] [B]false[/B];
    		[B]if[/B]([COLOR=#0086B3]eregi[/COLOR]([COLOR=#008080]$tld_array[/COLOR][[COLOR=#DD1144]"avail_response"[/COLOR]], [COLOR=#008080]$data[/COLOR]))
                [B]return[/B] [B]true[/B];
            [B]else[/B]
    			[B]return[/B] [B]false[/B];
    		[B]return[/B] [B]false[/B];
        }
    
    Code (markup):
    Thanks in advance, Please Help :)
     
    WebDevNow, Apr 25, 2012 IP
  2. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #2
    eregi is deprecated as of PHP 5.3

    use preg_match instead. Shouldn't be that hard to rewrite.
    http://at.php.net/manual/en/function.preg-match.php
    Code (markup):
     
    GMF, Apr 25, 2012 IP
  3. WebDevNow

    WebDevNow Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can you please Re-Write the Code for me with the change of eregi to preg-match,
    please let me know how it should be to work,
    as i had several trials but failed to put it working properly
    Thanks :)
     
    WebDevNow, Apr 25, 2012 IP
  4. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #4
    I think you should be able to do it yourself ;)
     
    GMF, Apr 25, 2012 IP
  5. WebDevNow

    WebDevNow Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If Im able to do it myself,
    I wouldnt asking for help in this forum,
    anyways thank you, i think that i will get more help from someone who appreciate helping others :)
    Thanks !!!
     
    WebDevNow, Apr 25, 2012 IP
  6. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #6
    You know the proverb: Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.

    I'll throw in a good PHP tutorial

    http://devzone.zend.com/6/php-101-php-for-the-absolute-beginner/
    http://tut.php-quake.net/en/post.html
    Code (markup):
    and a regular expression tutorial

    http://www.zytrax.com/tech/web/regex.htm
    Code (markup):
    With these you should be able to fish :eek:
     
    GMF, Apr 26, 2012 IP
  7. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #7
    If you read the documentation for preg_match, there shouldn't have much difference.

    It should look something like this in preg_match:
            if(!preg_match('/^[a-zA-Z0-9\-]{1,}$/', $domain))  return false;
            if(preg_match('/[-]{2,}/', $domain))               return false;
            if(preg_match('/^[-]{1,}/', $domain))              return false;
            if(preg_match('/[-]{1,}$/', $domain))              return false;
    PHP:
     
    Rainulf, Apr 26, 2012 IP