Enter your keyword

PHP

How to Marge two arrays in one array

$array1 = array("red", "shape", "color");
$array2 = array("a", "b",  "green", "trapezoid");
$result = array_merge($array1, $array2);
print_r($result); 

How to Search in Array

$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$key = array_search('green', $array); 

How to get CSV File Data in Php

$file_name = 'samplefile.csv';
 $row = 0;
if (($handle = fopen($file_name, "r")) !== FALSE) {
	 echo '<table>';
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        if($row == 0){ 
            $row++; 
            } else {
        echo '<tr>';
          echo '<td>'.$data[0].'</td>';
        echo '<td>'.$data[1].'</td>';
        echo '<td>'.$data[2].'</td>';
        echo '<td>'.$data[3].'</td>';
        echo '</tr>';
        }
}
    echo '</table>';
    } else {
    echo 'File could not be opened.';
    }	
    fclose($handle);

Instagram API how to get user ID?

function getInstaID($username)
{
    $username = strtolower($username); // sanitization
    $token = "InsertThatHere";
    $url = "https://api.instagram.com/v1/users/search?q=".$username."&access_token=".$token;
    $get = file_get_contents($url);
    $json = json_decode($get);
    $output = '';
    foreach($json->data as $user)
    {
    if($user->username == $username)
     {
     // $output .= $user->id 
       $output .= '<div class="result"> ';
       $output .= '<div class="id"><h4>User ID: '.$user->id.'<br></h4></div> ';
       $output .= '<div class="restults">';
       $output .= '<div class="avatar"> <img alt="" src="'.$user->profile_picture.'"></a></div>';
       $output .=	'<div class="text">Username: '.$user->username.'<br>Name: '.$user->full_name.'<br></div>';
       $output .=    '</div>';
       $output .= '</div>';
       //return $user->id;
        }
    }
    return $output; // return this if nothing is found
}

echo getInstaID('aliciakeys'); // this should print 20979117

 

How to User ID Encryption and Decryption

Use this Function in function.php

function user_encrypt($sData){
$idus=(double)$sData*425325.24;
return base64_encode($idus);
}

function user_decrypt($sData){
$url_id=base64_decode($sData);
$idus=(double)$url_id/425325.24;
return $idus;
}
echo user_encrypt($user_id);
echo user_decrypt($user_id);

How to Compression of js and css in using .htaccess

Add this code to your .htaccess file

RewriteEngine on
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.jgz -f
RewriteRule (.*).js$ $1.js.jgz [L]
AddType "text/javascript" .js.jgz
AddEncoding gzip .jgz

RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.jgz -f
RewriteRule (.*).css$ $1.css.jgz [L]
AddType "text/css" .css.jgz
AddEncoding gzip .jgz
Options -Indexes

CURL Request

$url='https://maps.googleapis.com/maps/api/place/textsearch/json?query='.$query1.'&sensor=true&key='.$key;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response);
echo '<pre/>'; print_r($response_a); die;