martes, 20 de noviembre de 2018

reading a file and printing specific values

<?php
// get contents of a file into a string
$filename = "./areacode.log";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);

$elements=explode("\n",$contents) ;
foreach($elements as $value) {
if (stristr($value,"California ")) {   // If  Number  California  is found it will print all values co Calif
echo "$value<br>";
}

}
?>

Original File
Alabama(1)251

Alabama(1)256

Alabama(1)334

Alaska(1)907

Arizona (1)480

Arizona (1)520

Arizona (1)602

Arizona (1)623

Arizona (1)928

Arkansas(1)479

Arkansas(1)501

Arkansas(1)870

California (1)209

California (1)213

California (1)310

California (1)323

California (1)408

California (1)415


domingo, 11 de noviembre de 2018

json encode y decode

<?php

$arr=array(6000=>"blocked",6001=>40000);

$info=json_encode($arr);

print_r($info);

$info=json_decode($info,true);

foreach($info as $key=>$value){
echo "<br><br>";
echo  "$key=>$value <br>";
}


?>

domingo, 23 de septiembre de 2018

asterisk xml loteria

#!/usr/bin/php -q
<?php
error_reporting(E_ALL);
set_time_limit(30);
require_once('/var/lib/asterisk/agi-bin/phpagi/phpagi.php');
$agi = new AGI();
$agi->answer();

$xmlstring=file_get_contents("http://190.131.219.198:5020/ApiRestBolivarApp/webresources/web.service.Bnet.bnetServiceSources/resultadosAyer");
$xml = simplexml_load_string($xmlstring);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
//print_r($array);
//print_r($array[resultadoLoteria][0]);

foreach($array[resultadoLoteria] as $key=>$value) {

foreach($array[resultadoLoteria][$key] as $key=>$value) {
if(!is_array($value)) {

$value=str_replace (" " ,"_",$value );

if($key=='nombreLoteria'){

 
$agi->stream_file($value);
}
sleep(1);
if($key=='resultado'){
$agi->say_digits($value);
}

sleep(1);

if($key=='serie'){
$agi->stream_file("serie");

$agi->exec("sayalpha","$value");


}
}
}
}
?>

<resultadoLoterias>
<resultadoLoteria>
<nombreLoteria>DORADO MANANA</nombreLoteria>
<resultado>8276</resultado>
<serie> </serie>
</resultadoLoteria>
<resultadoLoteria>
<nombreLoteria>CHONTICO</nombreLoteria>
<resultado>9304</resultado>
<serie> </serie>
</resultadoLoteria>
<resultadoLoteria>
<nombreLoteria>LA FANTASTICA DIA</nombreLoteria>
<resultado>1238</resultado>
<serie> </serie>
</resultadoLoteria>
<resultadoLoteria>
<nombreLoteria>PAISITA DIA</nombreLoteria>
<resultado>4608</resultado>
<serie> </serie>
</resultadoLoteria>
<resultadoLoteria>
<nombreLoteria>PIJAO</nombreLoteria>
<resultado>9477</resultado>
<serie>HAZ22 </serie>

lunes, 17 de septiembre de 2018

Ajax Pagination with Search and Filter in PHP

https://www.codexworld.com/ajax-pagination-with-search-filter-php/

get long and lat from place

http://www.mapcoordinates.net/en

HTML5 Geo Location

<!DOCTYPE html>
<html>
<body>

<p>Click the button to get your coordinates.</p>

<button onclick="getLocation()">Try It</button>

<p id="demo"></p>

<script>
var x = document.getElementById("demo");

function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}

function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude +
    "<br>Longitude: " + position.coords.longitude;
}
</script>

</body>
</html>

domingo, 16 de septiembre de 2018

PHP: Get Latitude/Longitude using Google Maps API


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$address = "Kathmandu, Nepal";
$url = "http://maps.google.com/maps/api/geocode/json?address=".urlencode($address);
<!--more-->
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$responseJson = curl_exec($ch);
curl_close($ch);
$response = json_decode($responseJson);
if ($response->status == 'OK') {
    $latitude = $response->results[0]->geometry->location->lat;
    $longitude = $response->results[0]->geometry->location->lng;
    echo 'Latitude: ' . $latitude;     
    echo '<br />';     
    echo 'Longitude: ' . $longitude;
} else {
    echo $response->status;
    var_dump($response);
    exit;
}

Display Google Map with Marker using Latitude & Longitude Coordinates

    <head>
        <title>Google Map</title>
        <meta name="viewport" content="initial-scale=1.0">
        <meta charset="utf-8">
        <style>          
          #map {
            height: 300px;    
            width: 600px;            
          }          
        </style>        
    </head>    
    <body>        
        <div style="padding:10px">
            <div id="map"></div>
        </div>
        
        <script type="text/javascript">
        var map;
        
        function initMap() {                            
            var latitude = 27.7172453; // YOUR LATITUDE VALUE
            var longitude = 85.3239605; // YOUR LONGITUDE VALUE
            
            var myLatLng = {lat: latitude, lng: longitude};
            
            map = new google.maps.Map(document.getElementById('map'), {
              center: myLatLng,
              zoom: 14                    
            });
                    
            var marker = new google.maps.Marker({
              position: myLatLng,
              map: map,
              //title: 'Hello World'
              
              // setting latitude & longitude as title of the marker
              // title is shown when you hover over the marker
              title: latitude + ', ' + longitude
            });            
        }
        </script>
        <script src="https://maps.googleapis.com/maps/api/js?key=YOUR-API-KEY&callback=initMap"
        async defer></script>
    </body>    
</html>