$url = "https://www.googleapis.com/urlshortener/v1/url"; $strPost = '{"longUrl": "YOUR LONG URL"}'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); //if your are using proxy url use proxy setting // curl_setopt($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HTTPGET,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/json")); //since i am requesting json response curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_POSTFIELDS, $strPost); // add POST fields curl_setopt($ch, CURLOPT_POST, 1); $result = curl_exec($ch); var_dump($result); curl_close($ch); exit; If you dont want to use the google url shortner want to create your own check it here : http://opendummies.blogspot.in/2014/07/creating-url-shortner.html |
All about very small logical and programming problems. Complex theories made simple to understand
Tuesday, June 25, 2013
Google shorten URL - a Simple CURL script
Thursday, December 6, 2012
Convert First letter a string to capital
Here is the function which is used to convert all the first letters of the name to capital Letters.
This idea of creating this function is inspired with the words of my colleague Kamal Relwani
This idea of creating this function is inspired with the words of my colleague Kamal Relwani
Sunday, November 4, 2012
How to create a facebook add friend request
Using JavaScript :
Things Required all u need to do i call
Things Required all u need to do i call
- Call FB.init Method -
FB.init({ appId : 'YOUR_APP_ID', frictionlessRequests : true });
- To send request for purticular friends
- function sendRequestToRecipients(){ FB.ui ({method: 'apprequests', message: 'My Request', to: '12345,23456' }, requestCallback); }
- To send request for all friends
function sendRequestViaMultiFriendSelector() { FB.ui({method: 'apprequests', message: 'My Request' }, callbackfunction()); }
callbackfunction(response){
alert(response);
}
Wednesday, October 3, 2012
Create a Date Drop down
Creating a Date year and Date drop down which is validated based on leap year and date
Here is the code please add jquery script tag before you include the code
function fnDate(){
try{
for(var i=1950;i<=2009;i++){
jq("#dobyy").append("<option value="+i+">"+i+"</option>");
}
for(var i=1;i<=12;i++){
jq("#dobmm").append("<option value="+i+">"+i+"</option>");
}
var month = '';
var year = '';
jq("#dobmm").change(function() {
month = jq("#dobmm").val();
year = jq("#dobyy").val();
var aOddMnth = ["1","3","5","7","8","10","12" ];
var aEvnMnth = ["4","6","9","11"];
jq("#dobdd").html("<select name=\"dobdd\" id=\"dobdd\" title=\"1\" style=\"width:84px;\"><option value=\"\">Day</option></ select> & nbsp;");
if(month > 0){
if(month == "2"){
if(year%4 == 0){
for(var i=1;i<=29;i++){
jq("#dobdd").append("<option value="+i+">"+i+"</option>");
}
}else{
for(var i=1;i<=28;i++){
jq("#dobdd").append("<option value="+i+">"+i+"</option>");
}
}
}
if(jq.inArray(month,aOddMnth) != -1){
for(var i=1;i<=31;i++){
jq("#dobdd").append("<option value="+i+">"+i+"</option>");
}
}
if(jq.inArray(month,aEvnMnth) != -1){
for(var i=1;i<=30;i++){
jq("#dobdd").append("<option value="+i+">"+i+"</option>");
}
}
}
});
}catch(e){
alert(e.message)
}
}
Here is the code please add jquery script tag before you include the code
function fnDate(){
try{
for(var i=1950;i<=2009;i++){
jq("#dobyy").append("<option value="+i+">"+i+"</option>");
}
for(var i=1;i<=12;i++){
jq("#dobmm").append("<option value="+i+">"+i+"</option>");
}
var month = '';
var year = '';
jq("#dobmm").change(function()
month = jq("#dobmm").val();
year = jq("#dobyy").val();
var aOddMnth = ["1","3","5","7","8","10","12"
var aEvnMnth = ["4","6","9","11"];
jq("#dobdd").html("<select name=\"dobdd\" id=\"dobdd\" title=\"1\" style=\"width:84px;\"><option value=\"\">Day</option></
if(month > 0){
if(month == "2"){
if(year%4 == 0){
for(var i=1;i<=29;i++){
jq("#dobdd").append("<option value="+i+">"+i+"</option>");
}
}else{
for(var i=1;i<=28;i++){
jq("#dobdd").append("<option value="+i+">"+i+"</option>");
}
}
}
if(jq.inArray(month,aOddMnth) != -1){
for(var i=1;i<=31;i++){
jq("#dobdd").append("<option value="+i+">"+i+"</option>");
}
}
if(jq.inArray(month,aEvnMnth) != -1){
for(var i=1;i<=30;i++){
jq("#dobdd").append("<option value="+i+">"+i+"</option>");
}
}
}
});
}catch(e){
alert(e.message)
}
}
Sunday, April 1, 2012
A simple Shopping Cart code in PHP
Here is a simple way to code to code the shopping cart i have seen in many websites for the code but i hope i have done using basic simple concepts of PHP to code the Shopping cart
Here is the link to download the source code - download
Instructions for using that code
Here is the link to download the source code - download
Instructions for using that code
- Extract the ca.rar
- place ca folder in www folder
- Execute the backup file or use scripts present in dbscripts folder to create new tables
- Now run localhost/ca to execute the code
Tuesday, March 27, 2012
Get Url From Browser in Php
Getting the URL from the parent window when you use a popup. This small Example code might help you to get the url from the parent window this can be used normal windows also
if(isset($_SERVER['HTTP_REFERER']))
{
$strPrevScheme = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_SCHEME);
{
$strPrevScheme = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_SCHEME);
$strPrevHost = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
$strPrevPath = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH);
$strPrevURL = urlencode($strPrevScheme.'://'.$strPrevHost.$strPrevPath);
}
}
the parse_url(url) gives the following array
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)
reference - http://in2.php.net/manual/en/function.parse-url.php
Monday, March 26, 2012
Finding the Count of all Charecters entered
<?php
/******************************************************************************
* Filename: totalnumberofalphabets.php
* Description: The file is used to count the number of occurences of each charecter
* Author: G Jayendra Kartheek
* Date Created: 26 Mar 2012
* Copyright © 2012 All rights reserved
******************************************************************************/
//after user submits the values
if (isset($_POST['butSubmit']) && '' != $_POST['butSubmit']) {
//taking the charecter into the array
$strValue = str_split($_POST['txtInput']);
//copying the string array
$strDuplicate = $strValue;
$iIntI = 0;
//based on the string length travesing the array
while ($iIntI < strlen($_POST['txtInput'])) {
//initializing the count and j for every iteration
$iCount = 0;
$iIntIIntJ = 0;
//comparing each and every element and finding the count of each element
while ($iIntIIntJ < strlen($_POST['txtInput'])) {
if ($strDuplicate[$iIntI] == $strValue[$iIntIIntJ]) {
$iCount++;
}
$iIntIIntJ++;
}
//printing the count
echo '<br>Number of times "' . $strDuplicate[$iIntI] . '" repeated is : ' . $iCount;
$iIntI++;
}
}
?>
<form name="" method ="POST">
<input type='text' name = 'txtInput'/><input type = 'submit' name= 'butSubmit' value ="OK"/>
</FORM>
Subscribe to:
Posts (Atom)