chrometweaks.org

Web iPage hosting service which allows scripts to communicate to other websites.?

Click Here To View All Answers...


My question is Web iPage hosting service which allows scripts to communicate to other websites.? Hoping for any response. Another question I got... I'm trying to take the customer-entered phone number from a customer's order ($order->customer['telephone']) and isolate the first 6 digits (area code and exchange) for use in submitting data to another program..

Since customers might enter their phone number in several different ways (800-555-1212, 800.555.1212, 8005551212, 800 555 1212), I need something that will just return the first 6 DIGITS that appear in that field, regardless of how they enter the information..

Any help GREATLY appreciated!..

Comments (217)

Good question... I dunno what is the right answer. I'll do some research and get back to you if I discover an answer. You should email the people at iPage as they probably can help you..

Comment #1

Thanks, Acheron!.

I'll give that a try (the first, simpler one, of course - the second one's still all "geek" to me)..

Comment #2

Well, I got close, but still have one little flaw somewhere it appears..

I have the following query.

$check_status_query = tep_db_query("select billing_name, billing_street_address, billing_city, billing_postcode, billing_state, billing_country, customers_telephone, customers_email_address from "TABLE_ORDERS" where orders_id = '"(int)$oID"'");.

       $check_status = tep_db_fetch_array($check_status_query);.

And I'm trying to accomplish what I mentioned above with.

$phstr = preg_replace ("/[^0-9] /i", ' ', $check_status['customers_telephone']);.

$phone = substr($phstr, 0, 6);.

Which then gets stored in a hash as.

$h["custPhone"] = $phone;     //set customer phone number.

I set debug on and it says that my entry (which was 800-555-1212) is being submitted as 800-55.

So something that I have above is not quite right..

Comment #3

Hehe well, the long function would go in /catalog/includes/application_top.php and would then be an available function in all of your catalog files..

Usage would be in place of this:.

$phone_string = substr($phone_string, 0, 6);.

So instead it would be ....

$phone_string = short_bychars($phone_string, 6);.

(the $tail option wouldn't be used here but it might be useful in other places, i.e. reviews or previews of items) For example ....

If you wanted to show only a piece of $long_string = supercalifragilistic, it would look like ....

$long_string = 'supercalifragilistic';.

$long_string = short_bychars($long_string, 6, ' ...');.

That would output.

Super .....

Comment #4

Ah right, it's counting the dash..

How about ...

$phstr = preg_replace ("/[[:alphanum:]] /i", ' ', $check_status['customers_telephone']);..

Comment #5

Or even better yet ....

$phstr = preg_replace( '/[^0123456789]/',$check_status['customers_telephone']);..

Comment #6

HMMM....

I'm sorry, but this is what I have now:.

The first one gives me.

And the second one gives me..

Comment #7

Well, I just kind of made the 1st one up, b/c I couldn't recall the proper format. hehe.

Just a typo on my part in the 2nd I think ??.

$phstr = preg_replace( '/[^0123456789]/', '', $check_status['customers_telephone']);.

Or.

$phstr = preg_replace("/[^0123456789] /i", '', $check_status['customers_telephone']);..

Comment #8

Acheron;.

Thank you so very much!!!.

The version with the single quotes seems to have done the trick.

$phstr = preg_replace( '/[^0123456789]/', '', $check_status['customers_telephone']);.

The double-quoted one still picked up the dash. I've only tried it with dashes, now I'll have to create some accounts with spaces, periods, etc. - just to check - and then onto finishing the modifications to the contribution that I needed this for..

Thanks again..

Comment #9

Np..

By the nature of the function above, it'll only allow one of those characters (numbers in this case) as a value so you should be all set..

Now you just have to hope that no one enters ....

1-800-555-1212.

You could of course add another function up top for ....

If pos 0 = '1' then replace with ''.

But only if needed and that's not a real fucntion so don't try it..

If it is needed, lmk and I'll write it up...

Comment #10

I'm trying to take the customer-entered phone number from a customer's order ($order->customer['telephone']) and isolate the first 6 digits (area code and exchange) for use in submitting data to another program..

Since customers might enter their phone number in several different ways (800-555-1212, 800.555.1212, 8005551212, 800 555 1212), I need something that will just return the first 6 DIGITS that appear in that field, regardless of how they enter the information..

Any help GREATLY appreciated!..

Comment #11

First you need a string to convert them all to the same format. So they will all look like:.

8005551212.

Something like ....

$phone_string = preg_replace("/[^0-9]/i",'',$phone_string);.

Then you need to pull just the first 6 digits with any one of a number of PHP functions. You can use a built in PHP function like ....

$phone_string = substr($phone_string, 0, 6);.

Or add a more complex function of your own that would be useful for other things as well. here's one I put together ....

   function short_bychars($text,$length=60,$tail) {.

   $text = trim($text);.

    $txtl = strlen($text);.

    if($txtl > $length) {.

      for($i=1;$text[$length-$i]!=" ";$i++) {.

        if($i == $length) {.

          return substr($text,0,$length)$tail;.

      }.

    }.

        $text = substr($text,0,$length-$i+1)$tail;.

    }.

    return $text;..

Comment #12


This question was taken from a support group/message board and re-posted here so others can learn from it.