lunes, 6 de enero de 2020

json array object

<?php


$data=array(array("name"=>"Ambiorix","Lastname"=>"Rodriguez","age"=>21));


$info=json_encode($data);

print_r("{info : ".$info."}");

?>

MYSQL to json Object array

<?php
$link = mysqli_connect("localhost", "root", "", "asteriskcdrdb");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
$cars=array();

$query = " select * from  cdr limit 5";

if ($result = mysqli_query($link, $query)) {

    /* fetch associative array */
    while ($row = mysqli_fetch_assoc($result)) {
        echo "$row[uniqueid], $row[src]<br>";
      $row[uniqueid]=array("src"=>$row[src],"dst"=>$row[dst]);

$cars[]=$row[uniqueid];


   }

    /* free result set */
    mysqli_free_result($result);
}

$info=json_encode($cars);

print_r($info);

//else {

// printf("Error: %s\n", mysqli_error($link));

//}


/* close connection */
mysqli_close($link);
?>


[{"src":"+16145993800","dst":"s"},{"src":"+16145993800","dst":"600"},{"src":"+16145993800","dst":"600"},{"src":"100","dst":"500"},{"src":"+16145993800","dst":"600"}]

domingo, 5 de enero de 2020

creating json array object

<?php


$cars=array(array("name"=>"Ambiorix","lastname"=>"Rodriguez","age"=>38));


$info=json_encode($cars);

print_r($info);

?>

[{"name":"Ambiorix","lastname":"Rodriguez","age":38}]

viernes, 3 de enero de 2020

allow numbers

106
You can use preg_replace in this case;
$res = preg_replace("/[^0-9]/", "", "Every 6 Months" );
$res return 6 in this case.
If want also to include decimal separator or thousand separator check this example:
$res = preg_replace("/[^0-9.]/", "", "$ 123.099");
$res returns "123.099" in this case
Include period as decimal separator or thousand separator: "/[^0-9.]/"
Include coma as decimal separator or thousand separator: "/[^0-9,]/"
Include period and coma as decimal separator and thousand separator: "/[^0-9,.]/"