libphonenumber js を php で使用して、ファイルからの番号のリストを検証します。
include 'SimpleXLSX.class.php';
$lines = array();
if(isset($_FILES['file']))
{
$filename = $_FILES['file']['name'];
$filetmpname = $_FILES['file']['tmp_name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
print_r($ext);
if($ext == 'csv')
{
$fr = fopen($_FILES['file']['tmp_name'], 'r+');
while( ($row = fgetcsv($fr, 8192)) !== FALSE )
{
$lines[] = $row;
}
}
else if($ext == 'xlsx')
{
$xlsx = new SimpleXLSX($filetmpname);
$rows = $xlsx->rows();
foreach ($rows as $row)
{
$lines[] = $row;
}
}
}
$objects = (object)$lines;
$number='';
foreach($objects as $object)
{
$number = $object[7];
if(<script> </script>');
var_dump($object[7]);
}
?>
<html>
<h2>libphonenumber Tool</h2>
<form action="" method="post" accept-charset="utf8" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="btn_submit" value="Upload File" />
<script src="goog/base.js"></script>
<script>
goog.require('goog.proto2.Message');
</script>
<script src="phonemetadata.pb.js"></script>
<script src="phonenumber.pb.js"></script>
<script src="metadata.js"></script>
<script src="phonenumberutil.js"></script>
<script src="asyoutypeformatter.js"></script>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script>
var number = <?php print_r(json_encode($number));?>;
var regionCode = null;
var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
/* Grab the parser. */
//var isNumberValid = phoneUtil.isValidNumber(myStr);
/* Parse the phone number. */
var proto = null;
try {
proto = phoneUtil.parse(number, "US");
// if(myStr = isNumberValid){console.log('succsess');}
} catch (error) {
proto = error.toString();
}
var isNumberValid = phoneUtil.isValidNumber(proto);
if(isNumberValid)
{
alert('Valid');
}
else{alert('not valid')};enter code here
</script>
php の各 $number を js の var 番号に渡して、php の if 文に true または false を返すようにしたいです。下手な英語でごめんなさい