var objJSON = eval("(function(){return " + resp + ";})()");
// resp is ajax reponse in json encoded by php "objJSON .name" to take values
Html, JAVA,DOTNET,Javascript, PHP, and JQuery Scripts and its issues with solutions
Monday, 25 August 2014
Thursday, 21 August 2014
Wednesday, 20 August 2014
Factorial program in c using for loop
#include <stdio.h> int main(){ int c, n, fact = 1; printf("Enter a number to calculate it's factorial\n"); scanf("%d", &n); for (c = 1; c <= n; c++) fact = fact * c; printf("Factorial of %d = %d\n", n, fact); return 0; }
Factorial program in c using function
#include <stdio.h> long factorial(int); int main(){ int number; long fact = 1; printf("Enter a number to calculate it's factorial\n"); scanf("%d", &number); printf("%d! = %ld\n", number, factorial(number)); return 0; } long factorial(int n){ int c; long result = 1; for (c = 1; c <= n; c++) result = result * c; return result; }
Factorial program in c using recursion
#include<stdio.h> long factorial(int); int main(){ int n; long f; printf("Enter an integer to find factorial\n"); scanf("%d", &n); if (n < 0) printf("Negative integers are not allowed.\n"); else{ f = factorial(n); printf("%d! = %ld\n", n, f); } return 0; } long factorial(int n){ if (n == 0) return 1; else return(n * factorial(n-1)); }
Tuesday, 19 August 2014
Page refresh by using Meta tag http-equiv="refresh"
<meta http-equiv="refresh" content="10" url="http://praba-2011.blogspot.in">
content="10" is after 10 secs page will be auto reload
content="10" is after 10 secs page will be auto reload
Input field JQuery float validation, decimal validation
$('#price').keyup(function(e){ var entered_value = $(this).val(); var regexPattern = /^\d{0,8}(\.\d{1,2})?$/; //Allow only Number as well 0nly 2 digit after dot(.) if(regexPattern.test(entered_value)) { alert("false") ; } else { alert("true"); } });
Monday, 18 August 2014
How to take dates between two dates in php?
$task_to_do = array(); echo "
"; $s = strtotime("START_DATE"); $d = strtotime("END_DATE"); $dif = 86400; $i=$s; $x=0; while ($i <= $d) { $dat = date("Y-m-d 00:00:00",$i); $t_s = date("Y-m-d 00:00:00",strtotime($dat)); $t_e = date("Y-m-d 23:59:59",strtotime($dat)); $task_to_do[$x]["start_date"] = $t_s; $task_to_do[$x]["end_date"] = $t_e; $i = $i+$dif; $x++; } echo ""; print_r($task_to_do);
Sunday, 17 August 2014
Disable Hotlinking Images from Searchengines with htaccess
The following code is used to prevent HotLinking to jpg, jpeg, gif, png, and bmp file types.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?your-websitename.com/.*$ [NC]
RewriteRule .(jpg|jpeg|gif|png|bmp)$ - [F]
Saturday, 16 August 2014
To add watermark image with original image by using php GD functions
$main_img = "Porsche_911_996_Carrera_4S.jpg"; // main big photo / picture $watermark_img = "watermark.gif"; // use GIF or PNG, JPEG has no tranparency support $padding = 80; // distance to border in pixels for watermark image $opacity = 20; // image opacity for transparent watermark $watermark = imagecreatefromgif($watermark_img); // create watermark $image = imagecreatefromjpeg($main_img); // create main graphic if(!$image || !$watermark) die("Error: main image or watermark could not be loaded!"); $watermark_size = getimagesize($watermark_img); $watermark_width = $watermark_size[0]; $watermark_height = $watermark_size[1]; $image_size = getimagesize($main_img); $dest_x = $image_size[0] - $watermark_width - $padding+10; $dest_y = $image_size[1] - $watermark_height - $padding-80; // copy watermark on main image imagecopymerge ($image, $watermark,$dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $opacity); // print image to screen header("content-type: image/jpeg"); imagejpeg($image); imagedestroy($image); imagedestroy($watermark);
To Crop image using PHP GD function
cropImage(150,100, 'example.png', 'png', 'image.png'); function cropImage($nw, $nh, $source, $stype, $dest) { $size = getimagesize($source); echo "
".$w = 500; echo "
".$h = 400; switch($stype) { case 'gif': $simg = imagecreatefromgif($source); break; case 'jpg': $simg = imagecreatefromjpeg($source); break; case 'png': $simg = imagecreatefrompng($source); break; } $dimg = imagecreatetruecolor($nw, $nh); echo "
".$wm = $w/$nw; echo "
".$hm = $h/$nh; echo "
".$h_height = $nh/2; echo "
".$w_height = $nw/2; if($w> $h) { echo "
".$adjusted_width = $w / $hm; echo "
".$half_width = ($adjusted_width / 2)+25; echo "
".$int_width = $half_width - $w_height; imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h); } elseif(($w <$h) || ($w == $h)) { $adjusted_height = $h / $wm; $half_height = $adjusted_height / 2; $int_height = $half_height - $h_height; imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h); } else { imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h); } imagejpeg($dimg,$dest,100); }
Thursday, 14 August 2014
Bootstrap Tab to set active & show its content in onload or onclick
<div> <ul class="nav nav-tabs" id="tabMenu"> <li class="active"><a href="#Home">Home</a></li> <li><a href="#Training">Training</a></li> <li class="dropdown"> <a data-toggle="dropdown" class="dropdown-toggle" href="#"> Placements <b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="#dotnet">DotNet</a></li> <li><a href="#android">Android</a></li> <li><a href="#java">Java</a></li> </ul> </li> </ul> <div class="tab-content"> <div id="Home" class="tab-pane fade in active"> <p>This is the Home page...</p> </div> <div id="Training" class="tab-pane fade"> <p>Please select your option regarding on Training...</p> </div> <div id="dotnet" class="tab-pane fade"> <p>Welcome to DotNet Placements Section...</p> </div> <div id="android" class="tab-pane fade"> <p>Welcome to Android Placements Section...</p> </div> <div id="java" class="tab-pane fade"> <p>Welcome to Java Placements Section...</p> </div> </div> </div> Showing Tab targeted by Selector: In order to show our tab manually on start or reload, we have to add the following script to the above code <script type="text/javascript"> $(document).ready(function () { $('#tabMenu a[href="#java"]').tab('show'); // showing the tab targeted by the selector }); </script> Showing First tab by Default: In order to show the First tab on page reload, Add the below script to the main source <script type="text/javascript"> $(document).ready(function () { $("#tabMenu a:first").tab('show'); // It show the first tab on Reload }); </script> Showing Last tab by Default: If we need to show the last tab on default, Change the Script like below, <script type="text/javascript"> $(document).ready(function () { $("#tabMenu a:last").tab('show'); // It show the Last tab on Reload }); </script> Showing Tabs based on Index: We can also show the Default Tab by using Index like in the below script, <script type="text/javascript"> $(document).ready(function () { $("#tabMenu li:eq(1) a").tab('show'); // It shows second tab (0-indexed, like an array) on Reload }); </script>
Wednesday, 13 August 2014
Make symbols with the help of Keyboard
Trademark Symbol | Alt+0153 | ™ |
Copyright Symbol | Alt+0169 | © |
Registered Trademark Symbol | Alt+0174 | ® |
Degree Symbol | Alt+0176 | ° |
Plus or Minus Sign | Alt+0177 | ± |
Paragraph Mark Symbol | Alt+0182 | ¶ |
Fraction three-fourths | Alt+0190 | ¾ |
Multiplication Sign | Alt+0215 | × |
The Cent Sign | Alt+0162 | ¢ |
Upside Down Exclamation Point | Alt+0161 | ¡ |
Upside Down Question mark | Alt+0191 | ¿ |
Smily face | Alt+1 | ☺ |
Black Smily face | Alt+2 | ☻ |
Sun | Alt+15 | ☼ |
Female Symbol | Alt+12 | ♀ |
Male Symbol | Alt+11 | ♂ |
Spade | Alt+6 | ♠ |
Club | Alt+5 | ♣ |
Heart | Alt+3 | ♥ |
Diamond | Alt+4 | ♦ |
Eighth Note | Alt+13 | ♪ |
Beamed Eighth Note | Alt+14 | ♫ |
Squareroot Check mark | Alt+251 | √ |
Up Arrow | Alt+24 | ↑ |
Down Arrow | Alt+25 | ↓ |
Right Arrow | Alt+26 | → |
Left Arrow | Alt+27 | ← |
Up/Down Arrow | Alt+18 | ↕ |
Left/Right Arrow | Alt+29 | ↔ |
Tuesday, 12 August 2014
Datatable jQuery Plugin set order example
$(document).ready(function() { $('#example').dataTable( { "order": [[ 3, "desc" ]] } ); } ); Plugin files: //code.jquery.com/jquery-1.11.1.min.js //cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js
Mysql get two column value in get single field
Table : user -------------- | Id | Name | -------------- | 1 | Test | | 2 | Test1 | | 3 | TEst2 | | 4 | Test3 | | 5 | Test4 | | 6 | Test5 | | 7 | Test6 | -------------- Query : selecr concat(id,":",name) as output from user Output: ------------ | output | ------------ | 1:Test | | 2:Test1 | | 3:TEst2 | | 4:Test3 | | 5:Test4 | | 6:Test5 | | 7:Test6 | ------------
Mysql get multi row value in get single field
Table : user -------------- | Id | Name | -------------- | 1 | Test | | 2 | Test1 | | 3 | TEst2 | | 4 | Test3 | | 5 | Test4 | | 6 | Test5 | | 7 | Test6 | -------------- Query : select group_concat(concat(id) SEPARATOR ',') from user Output: 1,2,3,4,5,6,7
Friday, 8 August 2014
To improve PHP Programming tip in 10 steps
1. Use an SQL Injection Cheat Sheet 2. Know the Difference Between Comparison Operators 3. Shortcut the else 4. Drop those Brackets 5. Favour str_replace() over ereg_replace() and preg_replace() 6. Use Ternary Operators 7. Memcached 8. Use a Framework 9. Use the Suppression Operator Correctly 10. Use isset instead of strlen
Thursday, 7 August 2014
Get thump image from youtube link
<?php $url = "YOU_TUBE_URL"; //Ex Youtube link: https://www.youtube.com/watch?v=vL-c_RtYkBE $queryString = parse_url($url, PHP_URL_QUERY); parse_str($queryString, $params); $v = $params['v']; if(strlen($v)>0){ echo "<img src='http://i3.ytimg.com/vi/$v/default.jpg' />"; echo "<img src='http://i3.ytimg.com/vi/$v/hqdefault.jpg' />"; echo "<img src='http://i3.ytimg.com/vi/$v/mqdefault.jpg' />"; echo "<img src='http://i3.ytimg.com/vi/$v/maxresdefault.jpg' />"; } ?>
Browser capture key events & key codes
$(document).keypress(function(e) { if (e.which == "13") { //enter pressed } });
Micromax Canvas HD Plus A190 Full details with price for Amazon, flipkart and sanpdeal
Price : Amazon : Rs. 10,923.00/- Buy Online Flipkart : Rs. 11,289.00/- Buy Online Snapdeal : Rs. 11,350.00/- Buy Online OS OS Name : Android Kitkat 4.4.2 OS Version : Anroid 4.4 Chipset Type : MTK Processor : 1.5GHz Hexa Core Camera Flash : Yes Autofocus : Yes Resolution, Recording & Playback : 1920X1088 Camera Resolution : 8MP (rear) & 2MP (front) Key Specs Screen Size : 12.7 cm (5) OS Name : Android Kitkat 4.4.2 Processor : 1.5GHz Hexa Core Camera Resolution : 8MP (rear) & 2MP (front) Battery Capacity : 2000mAh Connectivity Options : 3G/Bluetooth/Wi-Fi/USB DESIGN Screen Size : 12.7 cm (5) Colour Depth : 262k Screen Type : Capacitive Screen Resolution : 1280x720 MULTIMEDIA Video Resolution : 1080p Video Frame Rate : 30 fps FM : Yes Video Formats Supported : mp4,3gp Audio Formats Supported : Mp3/MID/AMR/AAC/WAV BATTERY Battery Capacity : 2000mAh Standby Time : 250hr* Talktime : 7hr* Connectivity Frequency Band : WCDMA 900/2100MHz GSM 850/900/1800/1900MHz Network : 3G HSPA : Yes Wi-Fi : Yes Bluetooth : V3.0 Location : GPS : Yes Connectivity Options : 3G/Bluetooth/Wi-Fi/USB Storage ROM : 8GB Internal Memory : 4.76GB (mass storage) Expandable Memory : 32 GB Sensors : G-Sensor, proximitysensor, light sensor RAM : 1GB Connectors USB V : Micro Dual SIM Support : Yes Ear Jack : 3.5 mm Applications Applications : Mi live, get it, Games club,Mi games, kingsoft-office , games (giga jump, jelly, marbles)
Wednesday, 6 August 2014
Wordwrap in CS3 Html style
<?php $t="LognTEXTLognTEXTLognTEXTLognTEXTLognTEXTLognTEXTLognTEXTLognTEXTLognTEXT"; echo "$t<br/>"; ?> <div style="width:100px;border:1px solid red;word-wrap: break-word;"> <?php echo $t; ?> </div>
Times ago jQuery plugin
<script type='text/javascript' src="jquery.min.js"></script> <script type='text/javascript' src="timeago/jquery.timeago.js"></script> <script type='text/javascript'> $(document).ready(function() { $("abbr.timeago").timeago(); $("time.timeago").timeago(); }); </script> <abbr class="timeago" title="July 17, 2008">6 years ago</abbr>
SMTP Host name by different mail server
Gmail: smtp.gmail.com
Yahoomail: smtp.mail.yahoo.com
Godaddy: relay-hosting.secureserver.net
Rediff: smtp.rediffmail.com
Yahoomail: smtp.mail.yahoo.com
Godaddy: relay-hosting.secureserver.net
Rediff: smtp.rediffmail.com
Get address by using lattitude and longitude Google APi
<?php echo getAddress("28.6100", "77.2300"); function getaddress($lat,$lng) { $url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.trim($lat).','.trim($lng).'&sensor=false'; $json = @file_get_contents($url); $data=json_decode($json); $status = $data->status; if($status=="OK") return $data->results[0]->formatted_address; else return false; } ?>
First Data Global Gateway - Payment gateway integration
lt;?php
ini_set('display_errors', '1');
$url = 'https://api.demo.globalgatewaye4.firstdata.com/transaction/v11';
$data = array(
"gateway_id" => "xxxxxxx", //YOUR GATEWAY ID
"password" => "xxxxxxxx", // YOOUR GATEWAY PASSWORD
"transaction_type" => "00",
"amount" => "11",
"cardholder_name" => "Test",
"cc_number" => "4111111111111111",
"cc_expiry" => "0314"
);
$data_string= json_encode($data);
// Initializing curl
$ch = curl_init( $url );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=UTF-8;','Accept: application/json' ));
// Getting results
$result = curl_exec($ch);
// Getting jSON result string
$data_string = json_decode($result);
if ($data_string) {
if ($data_string->bank_resp_code == '100') {
print('Approved!');
} else {
print($data_string->bank_message);
}
} else {
print($result);
}
?>
Facebook embed your website
Instead, I would try this site, iframehost, to install your Iframe and embed your blog. Log in to Facebook. Go to this page. Click “install page tab.” Choose the business page to which you want to embed your blog. Click “authorize the tab application.” In the bottom left-hand corner of the text box that appears, change the drop down menu to “only me.” Beside “page source” click on “URL” and enter the URL you want to embed. Change the tab name and image. You will also be able to change these later. Click “Save Settings” and then allow the application to access your business page. Go to your business page and check that your tab is working appropriately. Ref: http://writerswin.com/new-options-to-embed-your-website-on-facebook/
By using PHP unzip zip files with source code
<?php
$zip = new ZipArchive;
$res = $zip->open('demo.zip');
if ($res === TRUE) {
$zip->extractTo('test/');
$zip->close();
echo 'woot!';
} else {
echo 'doh!';
}
?>
$zip = new ZipArchive;
$res = $zip->open('demo.zip');
if ($res === TRUE) {
$zip->extractTo('test/');
$zip->close();
echo 'woot!';
} else {
echo 'doh!';
}
?>
Tuesday, 5 August 2014
Bootstrap Off Canvas nav toggle viewing windows size
$(document).ready(function () {
$('[data-toggle=offcanvas]').click(function () {
$('.row-offcanvas').toggleClass('active')
});
});
$('[data-toggle=offcanvas]').click(function () {
$('.row-offcanvas').toggleClass('active')
});
});
Monday, 4 August 2014
How to determine if an ip within specific range or not by using php?
$lower = "0.0.0.0.0";
$upper = "255.255.255.255";
$ip = "0.0.0.10";
$lower_dec = (float)sprintf("%u",ip2long($lower));
$upper_dec = (float)sprintf("%u",ip2long($upper));
$ip_dec = (float)sprintf("%u",ip2long($ip));
if( ($ip_dec>=$lower_dec) && ($ip_dec<=$upper_dec) ){
echo "True";
}else{
echo "False";
}
$upper = "255.255.255.255";
$ip = "0.0.0.10";
$lower_dec = (float)sprintf("%u",ip2long($lower));
$upper_dec = (float)sprintf("%u",ip2long($upper));
$ip_dec = (float)sprintf("%u",ip2long($ip));
if( ($ip_dec>=$lower_dec) && ($ip_dec<=$upper_dec) ){
echo "True";
}else{
echo "False";
}
Subscribe to:
Posts (Atom)