Php

PHP related contents

Subjects

Latest Asked Question

A : hello here is your solution, <?php function distance_bt_two_points($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo) { $longitude1 = deg2rad($longitudeFrom); $longitude2 = deg2rad($longitudeTo); $latitude1 = deg2rad($latitudeFrom); $latitude2 = deg2rad($latitudeTo); //Haversine Formula $dlong = $longitude2 - $longitude1; $dlati = $latitude2 - $latitude1; $val = pow(sin($dlati/2),2)+cos($lat1)*cos($lat2)*pow(sin($dlong/2),2); $res = 2 * asin(sqrt($val)); $radius = 3958.756; return ($res*$radius); } $latitudeFrom = 19.017656 ; //mumbai $longitudeFrom = 72.856178; //mumbai $latitudeTo = 28.615338; //delhi $longitudeTo = 77.193474; //delhi // Distance between Mumbai and Delhi echo(distance_bt_two_points( $latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo)." "."miles"); ?> OUTPUT : 717.3753011057 miles
45 Likes
A : <?php $valid_passwords = array ("mario" => "carbonell"); $valid_users = array_keys($valid_passwords); $user = $_SERVER['PHP_AUTH_USER']; $pass = $_SERVER['PHP_AUTH_PW']; $validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]); if (!$validated) {   header('WWW-Authenticate: Basic realm="My Realm"');   header('HTTP/1.0 401 Unauthorized');   die ("Not authorized"); } // If arrives here, is a valid user. echo "<xmp>Welcome $user."; echo "<xmp>Congratulation, you are into the system."; ?>
45 Likes
A : hi just use this function: function timeConversion($input) {         $uSec = $input % 1000;         $input = floor($input / 1000);         $seconds = $input % 60;         $input = floor($input / 60);         $minutes = $input % 60;         $input = floor($input / 60);         $hour = $input;         return $hour.'Hrs '.$minutes.'Mins '.$seconds.'Sec';     }
45 Likes
A : Hi simple method just use this code <?php echo date("t") - date("j"); ?>
45 Likes
A : Hi simple code is here <?php $d=cal_days_in_month(CAL_GREGORIAN,date("m", strtotime("next month")),date("Y")); ?>
45 Likes
A : hi  firstly load image or file at local using  file_get_contents(); php function  ex :  $x  = file_get_contents(("http://fresheats.com/images/watermark.png"); imagecreatefrompng($x); It will work.
45 Likes
A : <?php echo strip_tags("Hello <b>world!</b>"); ?> This function strips a string from HTML, XML, and PHP tags. In this example, the <b> tag gets stripped  
45 Likes
A : Try this also $add_date = date("Y-m-d H:m:s"); $expiry_date = new DateTime($add_date); $expiry_date ->modify("+60 days"); echo $expiry_date ->format("Y-m-d H:m:s");
45 Likes
A : For example $users = array( array( 'userid' => '100', 'name' => 'Sandra Shush', ), array( 'userid' => '5465', 'name' => 'Stefanie Mcmohn', ), array( 'userid' => '40489', 'name' => 'Michael', ) ); $key = array_search(40489, array_column($users, 'uid')); echo $users[$key]['name']; Output: Sandra Shush.
45 Likes
A :   Hi try this php code... public function sendiOSNotification($registatoin_ids=null,$notification=null){             $deviceToken = '7eea2901746f503a94f8160d4932aa89e5091d5002ddc5a958c715d69a27e11a';           /*     ssl://gateway.sandbox.push.apple.com:2195 - development             ssl://gateway.push.apple.com:2195 - production. */                    $ctx = stream_context_create();         // ck.pem is your certificate file         stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');         stream_context_set_option($ctx, 'ssl', 'passphrase', 'testing');         // Open a connection to the APNS server         $fp = stream_socket_client(         'ssl://gateway.sandbox.push.apple.com:2195', $err,         $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);         if (!$fp)         exit("Failed to connect: $err $errstr" . PHP_EOL);         // Create the payload body         $body['aps'] = array(             'alert' => array(                 'title' =>'title',// $notification['Title'],                  'body' => 'body',//$notification['Body'],                 'type' => 'testing',//$notification['Type'],             ),             'sound' => 'default'         );         // Encode the payload as JSON         $payload = json_encode($body);         // Build the binary notification         $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;         // Send it to the server         $result = fwrite($fp, $msg, strlen($msg));                      // Close the connection to the server         fclose($fp);                      if (!$result){                     return 'Message not delivered' . PHP_EOL;         }         else{        return 'Message successfully delivered' . PHP_EOL;          }     } Note : Give Correct path of ck.pem file for local_cert. Note : Give correct passphrase certificate password. Note : Production URL :  ssl://gateway.push.apple.com:2195 Note : Development URL : ssl://gateway.sandbox.push.apple.com:2195
45 Likes
A : And finally with PHP 7 you can use the spaceship operator: usort($myArray, function($a, $b) { return $a["order"] <=> $b["order"]; });
45 Likes
A : here is code... $amount = 25.1236456; echo round($amount,2); result: 25.12
45 Likes
A :   Here is the code for merge array... <?php  $result = array_merge($arr1,$arr2,$arr3); ?>
45 Likes
A : use this split function in php to convert word into array. str_split("cool", 1); here 1 means break each word. Result : Array ( [0] => c [1] => o [2] => o [3] => l )
45 Likes
A : <?php $str = "Hello world. It"s a beautiful day."; print_r (explode(" ",$str)); ?> Result: Array ( [0] => Hello [1] => world. [2] => It"s [3] => a [4] => beautiful [5] => day. )
45 Likes
A : UPDATE mytable SET logins = logins + 1 WHERE id = 12
45 Likes
A : Using following code you get result $array = array(12,43,66,21,56,43,43,78,78,100,43,43,43,21); $vals = array_count_values($array); print_r($vals); Result: No. of NON Duplicate Items: 7 Array ( [12] => 1 [43] => 6 [66] => 1 [21] => 2 [56] => 1 [78] => 2 [100] => 1 );
45 Likes
A : $d=cal_days_in_month(CAL_GREGORIAN,date("7"),date("2018")); echo $d; Result: 31 Enjoy :)
45 Likes
Php Related Topic's