Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Get all Country List using php

<?php
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://restcountries.eu/rest/v2/all?',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
));

$response = curl_exec($curl);

curl_close($curl);
//echo $response;

$arr = json_decode($response);
?>

 <select  class="form-control" id="Country">
 <option>Select Country</option>
 <?php
 $i=0;
 while($i!=sizeof($arr))
 {
 ?>
 <option value="<?php echo $arr[$i]->callingCodes[0];?>"><?php echo $arr[$i]->name;?></option>
 <?php
 $i=$i+1;
 }
 ?>
 </select>
 
PREVIOUS NEXT
Tagged: #Get #Country #List #php
ADD COMMENT
Topic
Name
1+2 =