I have a file there is data, I add it to the database by criteria, there are 4 criteria

data

I add them to the database according to the criteria in CONTACT_TYPE I normalize by numbers, for example, if only numbers then = 3

if you have @ = 4, etc.

Please help with this question, if the digit is less than two digits then the criterion = 2 For example, if the digit is 1 or 12 in the file then the criterion = 2

enter image description here

if(isset($lstContact[0])) { for ($i=0;$i<=count($lstContact)-1;$i++) { $contacttype="0"; if(substr($lstContact[$i],0,1)=='+') $contacttype=2; if(strpos($lstContact[$i],'@')){ $contacttype=4; if ($CONTACTSmail=='') $CONTACTSmail= $lstContact[$i]; } if((strpos($lstContact[$i],'+')===false) && (strpos($lstContact[$i],'@')===false) && ($i!=0)) $contacttype=3; if($i==0) $contacttype=1 } } 
  • The first thing that came to mind was to compare numbers with 10 (<10 || <= 9 == true) - InDevX

1 answer 1

Just write in the program exactly what you say in your own words:

 if (preg_match("/^\d{1,2}$/", $lstContact[$i])) { $contacttype = 2; } 

Namely: if the entire contents of the line from its beginning /^ to its end $/ are the digits \d of one or two {1,2} , then the type of contact = 2 .