简体   繁体   中英

Send SMS to phone - php form removing ( ) and - from the phone number submitted

I have a script that I found online, that is trying to get the 10 digit phone number and then adding the Mobile provider to send an email to SMS.

It works. But...

My front end form is automatically inputing the "(", ")" and "-" parentheses and dashes to make it look more like a phone number. The php script isn't working because you have to send the email with none of that, only 0,1,2,3,4,5,6,7,8,9 works.

You can see the front end form here. http://busetopizza.com/demo/index.php by clicking the "Send To Phone"

You notice it will send the (516)-233-2333 as the for submission.

I need help rewriting the code toto strip out the characters, then re-evaluate it into something so it will send as 5162332333.

Attached is the php code.. Can this be done????

<?php
if (!isset($_POST['submit'])){error("Must use form to get here!");}
$ph = $_POST['10digit'];
$carrier = $_POST['carrier'];
switch ($carrier){
    case 'att':
        $to = $ph . '@txt.att.net';
        break;
    case 'metropcs':
        $to = $ph . '@mymetropcs.com';
        break;
    case 'nextel':
        $to = $ph . '@messaging.nextel.com';
        break;
    case 'sprint':
        $to = $ph . '@messaging.sprintpcs.com';
        break;
    case 'tmobile':
        $to = $ph . '@tmomail.net';
        break;
    case 'verizon':
        $to = $ph . '@vtext.com';
        break;
    case 'virgin':
        $to = $ph . '@vmobl.com';
        break;      
    default:
        error("No carrier selected, message not sent!");
}
$message = "http://www.busetopizza.com/";
$subject = "Send To Phone App";
$from = "admin@messtudios.com";
mail($to, $subject, $message, $from);
echo "Your message has been sent!";
exit();
function error($msg){
    echo "An error has occurred: ".$msg;
    exit();
}
?>

编辑以下行以使用正则表达式查找并替换输入中的所有非数字字符。

$ph = preg_replace('/[^[:digit:]]/', '', $_POST['10digit']);

You could use a Regular Expression to remove non-numeric digits from your input.

$pattern = '/[^0-9]*/';
$ph =  preg_replace($pattern,'', $_POST['10digit']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM