我目前正在使用API为我的SMS线索获取移动运营商。我已经有向服务发出API请求以获取移动运营商的代码,当我将其与单个输入字段一起使用时,它可以正常运行。但是,现在我想实现一个textarea,其中每个逗号后都有一个电话号码,并且它将数字导出到一列中,并将相应的运算符导出到另一列中。
电话号码格式为英国
+447000000000
API文档: numverify.com/documentation
如何将所有结果以以下格式导出到CSV或Excel文件:
+---------------------+-----------------------------------------+
|phone number 1 here | mobile operator for phone number 1 here |
+---------------------+-----------------------------------------+
|phone number 2 here | mobile operator for phone number 2 here |
+---------------------+-----------------------------------------+
|phone number 3 here | mobile operator for phone number 3 here |
+---------------------+-----------------------------------------+
当前代码:
<?php
// set API Access Key
$access_key = 'myapikeyhere';
if(isset($_POST['check'])){
// set phone number
$phone_numbers = explode(",", $_POST['numbers']);
foreach($phone_numbers as $key=>$phone_number) {
// Initialize CURL:
$ch = curl_init('http://apilayer.net/api/validate?access_key='.$access_key.'&number='.$phone_number.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Store the data:
$json = curl_exec($ch);
curl_close($ch);
// Decode JSON response:
$validationResult = json_decode($json, true);
// Access and use your preferred validation result objects
// $validity = $validationResult['valid'];
// $country_code = $validationResult['country_code'];
$carrier = $validationResult['carrier'];
}
}
?>
<form method="post">
<textarea rows="40" cols="20" name="numbers"></textarea>
<button type="submit" name="check">Check</button>
</form>