linuxmaster1979 Posted December 18, 2003 Share Posted December 18, 2003 I'm working trying to write an expression to match phone numbers in 2 different tables to checkout of a shopping cart using a customer credit line (based on the Net Terms module). I'm having trouble on the line beginning with $match (in red) in getting it in the write syntax. If you're familiar with regular expressions I could use a hand. Thanks! The Code: $customer = tep_db_query("select customers_telephone from " . TABLE_CUSTOMERS . " where customers_id ='" . $customer_id . "'"); if ($row = mysql_fetch_array($customer)) { $match = $row["customers_telephone"] && ereg ("${4,}", $customers_telephone); } $customer_credit = false; $check_credit = tep_db_query("select customers_credit_status, customers_credit_left from customers_credit where customers_credit_telephone ='" . $match . "'"); $credit = tep_db_fetch_array($check_credit); if ($credit['customers_credit_status'] == "yes" || $credit['customers_credit_status'] == "no"){ $credit_allowed = 'true'; } else { $credit_allowed = 'false'; } Knowledge Base | Contributions | Tips & Tricks Forum There are things known and there are things unknown, and in between are the doors. -- Jim Morrison Link to comment Share on other sites More sharing options...
Mark Russell Posted December 18, 2003 Share Posted December 18, 2003 Try this: Search for telephone number of the form XXX-XXX-XXXX, assuming you force the customer to enter in that specific format. ereg ("([0-9]{3})-([0-9]{3})-([0-9]{4})", $customers_telephone) hth, Mark Link to comment Share on other sites More sharing options...
Mark Russell Posted December 18, 2003 Share Posted December 18, 2003 Try this: Search for telephone number of the form XXX-XXX-XXXX, assuming you force the customer to enter in that specific format. ereg ("([0-9]{3})-([0-9]{3})-([0-9]{4})", $customers_telephone) Actually, that regex may represent (XXX)-(XXX)-(XXXX). Try this also for phone format (XXX)-XXX-XXXX: ereg ("([0-9]{3})-[0-9]{3}-[0-9]{4}", $customers_telephone) Mark Link to comment Share on other sites More sharing options...
linuxmaster1979 Posted December 18, 2003 Author Share Posted December 18, 2003 Hi Mark, I think you're on track for what I'm looking for, I've changed up the logic a little bit to get to the end result better. The areas where you see EXPRESSION is what I'm needing. I'm trying to figure out the syntax of a preg expression to make a variable out of a phone number that eliminates all the (, ), and - in it and only pulls the last 10 digits. So a listing in the database would look like (214) 887-9897 But, I need the variable to echo 2148879897 As well as 1-887-554-5533 would look like 8875545533 Here's my new code: $customer_telephone = tep_db_query("select customers_telephone from " . TABLE_CUSTOMERS . " where customers_id ='" . $customer_id . "'"); if ($row = mysql_fetch_array($customer_telephone)) { $customer_num = $row["customers_telephone"]; $adjust_customer = preg_match ("EXPRESSION", $customer_num); } $credit_telephone = tep_db_query("select customers_credit_telephone from customers_credit"); if ($row = mysql_fetch_array($credit_telephone)) { $credit_num = $row["credit_telephone"]; $adjust_credit = preg_match ("EXPRESSION", $credit_num); } $customer_credit = false; $check_credit = tep_db_query("select customers_credit_status, customers_credit_left from customers_credit where '" . $adjust_credit . "' ='" . $adjust_customer . "'"); Knowledge Base | Contributions | Tips & Tricks Forum There are things known and there are things unknown, and in between are the doors. -- Jim Morrison Link to comment Share on other sites More sharing options...
linuxmaster1979 Posted December 18, 2003 Author Share Posted December 18, 2003 Actually instead of the preg_match, it might actually need to be something like preg_replace. I'm still pretty new to php, so I'm learning it as I go..... Knowledge Base | Contributions | Tips & Tricks Forum There are things known and there are things unknown, and in between are the doors. -- Jim Morrison Link to comment Share on other sites More sharing options...
paulm2003 Posted December 18, 2003 Share Posted December 18, 2003 So a listing in the database would look like (214) 887-9897But, I need the variable to echo 2148879897 As well as 1-887-554-5533 would look like 8875545533 a simple string replace could do the above (fast and easy) Not sure how to do the ")" and "(" at the moment, but it should not be difficult I think. $value = str_replace('-','',$value); Also $value = ereg_replace('[^[:alnum:]]', "", $value); strips all non-alpha & non-numeric should work. Or do I misunderstand what you are looking for? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.