Friday 30 September 2016

How to use php varible in javascript.

<?php
$varible = "get any string or fetch any data from database";

   ?>
       <script type="text/javascript">
   var show= "<?php echo strip_tags($varible); ?>";
  alert(show);
  </script>

How to use javascript Function in php

<a href="javascript:readmore(id)"> Read More </a>

<script type="text/javascript">
function readmore(id)
{
 if(confirm('Sure To Remove This Chat ?'))
     {
        window.location.href='?readmore='+id;
      }
}
</script>

Tuesday 13 September 2016

how to share any post on facebook in php

<?php
$data = "pppppppppppppppppppppppppppp";

?>
<html>
     

<head>
    <title>Facebook Share Button - External Website</title>
   
<style type="text/css">

body { 
background:#f5f5f5;
font: 14px/150% 'century gothic',helvetica,arial;
}

#container {
margin:5px auto;
padding:25px;
width:400px;
border:1px solid #999;
border-radius:8px; -moz-border-radius:8px; -webkit-border-radius:8px;
background:#fff;
}
</style>


</head>

<body>

<div id="container">

<p>Manjeet kashyap</p>

<div id="fb-root"></div>


<script>
 window.fbAsyncInit = function() {
FB.init({

 appId  : '964579503687504',
 status : true, // check login status
 cookie : true, // enable cookies to allow the server to access the session
 xfbml  : true  // parse XFBML
});
 };

 (function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
 }());
</script>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>

<img id = "share_button" src = "http://app.tabpress.com/fbui_share/share_button.png">

<script type="text/javascript">
$(document).ready(function(){
$('#share_button').click(function(e){

e.preventDefault();
var m = "<?php echo $data; ?>";
FB.ui(
{

method: 'feed',
name: 'HyperArts Blog',
link: 'http://hyperarts.com/blog',
picture: 'http://www.hyperarts.com/_img/TabPress-LOGO-Home.png',
caption: 'I love HyperArts tutorials',
description: m,
message: ''
});
});
});
</script>


</div>

</body>
</html>

Friday 9 September 2016

how to check email valid on server in php.

$email = "john@gmail.com";

if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
  echo("$email is a valid email address");
} else {
  echo("$email is not a valid email address");
}

Tuesday 6 September 2016

how to call page content in template file in wordpress.

<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>

Sunday 21 August 2016

how to get address from latitude and longitude.

$geocode=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng=30.6978446,76.717779&sensor=false');

$output= json_decode($geocode);
//print_r($output);
echo $output->results[0]->formatted_address;

how to get latitude and longitude from Address .

$address = 'sector 70 mohali';

$geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false');

$geo = json_decode($geo, true);

if ($geo['status'] == 'OK') {
 $latitude = $geo['results'][0]['geometry']['location']['lat'];
 $longitude = $geo['results'][0]['geometry']['location']['lng'];
}

Tuesday 9 August 2016

how to create REST API in php

Simple three Step create Rest API 

STEP->1 create config.php

STEP-> 2create api.php

STEP-> 3create class.api.php


how to create php mysql connection with object

<?php
$host ='localhost';
$username ='username?';
$password ='password?';
$db = 'databasename?';
$con = new mysqli($host, $username, $password, $db);
if(mysqli_error($con))
{
printf("Connect failed %s\n",mysqli_connect_error());
}
?>