Jump to content

eregi to preg_match


Kingy

Recommended Posts

I'm creating a domain lookup script from a php class I found online.

 

Only problem with it is the fact that it uses the eregi function which I no is going out of fashion. Now i've never really used either eregi or preg_match so I have no idea how to convert one into the other.

 

if (eregi('^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$',$domain) != 1){

 

if(eregi($this->ext['.'.$domain_domain][1], $f_result)){

 

I've had a play with both of them and usually end up getting an error about using backslashes or something. I no it means that I need to escape the characters, but its just really confusing me.

 

Can anybody help me out. Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/193602-eregi-to-preg_match/
Share on other sites

Ok i've managed to make the first one work. Still having confusion issues with the seond. For anyone that needs to know..

 

Before:

if (eregi('^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$',$domain) != 1){

 

After:

if (preg_match("/^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$/i", $domain) != 1){

Link to comment
https://forums.phpfreaks.com/topic/193602-eregi-to-preg_match/#findComment-1019198
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.