Remove all non-numeric characters from a field

后端 未结 4 685
失恋的感觉
失恋的感觉 2020-12-17 18:16

I have a results set from a webform that includes a phone number for each set. the format of this phone number is not enforced (some are xxxxxxxxxx, some are (xxx)xxx-xxxx a

4条回答
  •  伪装坚强ぢ
    2020-12-17 18:55

    This may work but little tedious:

    Get the list of number from the table

    $result = mysql_query("Select ID, number from Table"); 
    

    On each value

    while ($row = mysql_fetch_array($result)) { 
    $ID = $row["ID"]; 
    $NUM = $row["number"]; 
    

    Then do a regex pattern and update that value to the ID

    $NUM = eregi_replace("whateverregex","",$NUM); 
    
    $sql = mysql_query("Update Table set number = $NUM where ID = $ID"); 
    } 
    

提交回复
热议问题