Monday, 23 November 2015

smileys for chat script using php

<?php function parseString($message ) {
    $my_smilies = array(
        ':)' => '<img src="images/smiley.gif" alt="" />',
    ':(' => '<img src="images/sad.gif" alt="" />',
   
    );

    return str_replace( array_keys($my_smilies), array_values($my_smilies), $message);
}

echo parseString($message);
?>

Thursday, 8 October 2015

How to make an autocomplete address field with google map api

<script src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places" type="text/javascript"></script>
        <script type="text/javascript">
               function initialize() {
                       var input = document.getElementById('searchTextField');
                       var autocomplete = new google.maps.places.Autocomplete(input);
               }
               google.maps.event.addDomListener(window, 'load', initialize);
       </script>
 <body>
               <div>
                       <input id="searchTextField" type="text" size="50" placeholder="Enter a location" autocomplete="on">
               </div>
           </body>

Wednesday, 30 September 2015

get distance between two address through google api in php

<?php
function get_distance($address1,$address2)
{
$address1_encode = urlencode($address1);
$address2_encode = urlencode($address2);
$addresses_string = "?origins=".$address1_encode."&destinations=".$address2_encode."&key=AIzaSyBf6kfop46PNbRUAG-VwHVrGlyvNunpw9o";
    $url = "https://maps.googleapis.com/maps/api/distancematrix/json".$addresses_string;
    $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);
   
  return $response;
    //$status = $response_a->status;
}
if(isset($_POST['get_dis'])){
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$results = get_distance($address1,$address2);
$response_a = json_decode($results);

echo "status :- ";
echo $result_status = $response_a->status;
echo "<br/>";
echo "distance :- ";
echo  $distance = $response_a->rows[0]->elements[0]->distance->value;
echo " M";
}
 ?>
 <form action="" method="post">
 <input type="text" name="address1">&nbsp;&nbsp;&nbsp;
 <input type="text" name="address2">&nbsp;&nbsp;&nbsp;
 <input type="submit" name="get_dis" value="Get Distance">

 </form>

Monday, 28 September 2015

javascript add class step by step in loop.

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$(function () {
  var $anchors = $('.anchor');

  (function _loop(idx) {
    $anchors.removeClass('highlight').eq(idx).addClass('highlight');
    setTimeout(function () {
      _loop((idx + 1) % $anchors.length);
    }, 2000);
  }(0));
});
</script>
<style>
.highlight{
color:#FF0000;
font-size:24px;
}
</style>
<a class="anchor">A</a>
<a class="anchor">B</a>
<a class="anchor">C</a>
<a class="anchor">D</a>
<a class="anchor">E</a>
<a class="anchor">F</a>
<a class="anchor">G</a>

Wednesday, 5 August 2015

how to import sql file in database in php

function  import_db($mysql_username,$mysql_password,$mysql_host,$mysql_database)
{
    // Name of the file
    $filename = $file_path.'/sql/database.sql';
   

    // Connect to MySQL server
    $db_conn = mysqli_connect($mysql_host, $mysql_username, $mysql_password,$mysql_database) or die('Error connecting to MySQL server: ' . mysql_error());
    // Select database
    //mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());

    // Temporary variable, used to store current query
    $templine = '';
    // Read in entire file
    $lines = file($filename);
    // Loop through each line
    foreach ($lines as $line)
    {
    // Skip it if it's a comment
    if (substr($line, 0, 2) == '--' || $line == '')
        continue;

    // Add this line to the current segment
    $templine .= $line;
    // If it has a semicolon at the end, it's the end of the query
    if (substr(trim($line), -1, 1) == ';')
    {
        // Perform the query
        mysqli_query($db_conn,$templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
        // Reset temp variable to empty
        $templine = '';
    }
    }
    //echo "Tables imported successfully";

}

Thursday, 18 June 2015

html value set in php variable

<?php
$my_var = <<<EOD
<div onclick="pa('1','sdsa','12');">SOME HTML</div>
EOD;

echo $my_var;
?>

Saturday, 13 June 2015

redirect www to non www htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]