Skip to main content

Posts

Encode and Decode of data URLs using Base64 in PHP

base64_encode and base64_decode: (PHP 4, PHP 5, PHP 7) base64_encode — Encodes data with MIME base64 Syntax: string base64_encode ( string $data ) Encodes the given data with base64.   Example: <?php $str = 'eabhyas.blogspot.com'; echo base64_encode($str); ?> Output:   ZWFiaHlhcy5ibG9nc3BvdC5jb20= (PHP 4, PHP 5, PHP 7) base64_decode — Decodes data encoded with MIME base64 Syntax: string base64_decode ( string $data [, bool $strict = false ] ) Decodes a base64 encoded data . Example: <?php $str = 'ZWFiaHlhcy5ibG9nc3BvdC5jb20='; echo base64_decode($str); ?> Output:   eabhyas.blogspot.com Function : <? function sscb64ende($s,$t=0){     if($t==0){         $v=base64_encode($s);         $v = strtr($v, '+/=', '-_,');     } else {         $v = strtr($s, '-_,', '+/=');         $v=base64_decode($v);     } return $v; } ?>

Multidimensional Array Searching - Find key by specific value

Solution is based on the array_search() function. You need to use PHP 5.5.0 or higher. $userdb=Array ( (0) => Array     (         (uid) => '100',         (name) => 'Sandra Shush',         (url) => 'urlof100'     ), (1) => Array     (         (uid) => '5465',         (name) => 'Stefanie Mcmohn',         (pic_square) => 'urlof100'     ), (2) => Array     (         (uid) => '40489',         (name) => 'Michael',         (pic_square) => 'urlof40489'     ) ); Solution-1: function myfunction($products, $field, $value) {    foreach($products as $key => $product)    {       if ( $product[$field] === $value )          return $key;    }    return false; }   Solution-2: $key = array_search(40489, array_column($userdb, 'uid')); echo ("The key is: ".$key); //This will output- The key is: 2 The function array_search() has two arguments. The first one is the value that yo

What is an earthquake?

Earthquakes with magnitude of about 2.0 or less are usually called microearthquakes; they are not commonly felt by people and are generally recorded only on local seismographs. Events with magnitudes of about 4.5 or greater - there are several thousand such shocks annually - are strong enough to be recorded by sensitive seismographs all over the world. Great earthquakes, such as the 1964 Good Friday earthquake in Alaska, have magnitudes of 8.0 or higher. On the average, one earthquake of such size occurs somewhere in the world each year. Magnitude measures the energy released at the source of the earthquake as determined from measurements on seismographs. An earthquake has one magnitude. The magnitude scale most commonly in use now is called the moment magnitude scale. Moment is a physical quantity proportional to the slip on the fault times the area of the fault surface that slips; it is related to the total energy released in the EQ. The moment magnitude p