Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Tuesday, October 9, 2012

PHP Web Developer, Wordpress, PHP Development India,Website Designing

Wednesday, April 11, 2012

How to grab tweets from Twitter using php

$tweets = 
json_decode(file_get_contents 
('http://twitter.com/statuses/user_timeline.json?
screen_name=USERNAME&count=10'));

var_dump($tweets);
 
 
//json_decode(file_get_contents()) function 

Tuesday, January 24, 2012

PHP array functions

PHP array  samples
 1) Desplaing the array in order, with out using sort functions
<?php
$array=array(1,20,5,16,7,19,3);
$cnt = count($array) - 1;
$FinalTemp = array();
for ($i = 0; $i <= $cnt; $i++) {
foreach($array as $key=>$value)
{
     if($value==max($array))
 {
  $sort[] = max($array);
  unset($array[$key]);
  }
}
}
 print_r($sort);
?>

2) In the main array, First delete one array values and then add other array values to the main array.
<?php
$array=array(5,4,5,7,3,6,4,1,8,4,5,6,2,1);
$delete=array(4,5,6);
$add=array(11,12,12,18);

foreach($array as $k=>$val)
{
if(in_array($val, $delete))
{
unset($array[$k]);
}
}
$result = array_merge((array)$array, (array)$add);
arsort($result);
print_r($result);
?>


3) array_count_values — Counts all the values of an array

<?php
$arr=array(a,c,k,n,n,h,r,a,a,a,c,h,b,h,k,n);
print_r(array_count_values($arr));
?>

Saturday, January 21, 2012

Simple rewriting using .htaccess


All requests to whatever.htm will be sent to whatever.php:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [NC]

The [NC] part at the end means "No Case", or "Case-Insensitive".
Requests to the .html automatically rewrite to .php. 
Ex: If it is whatever.htm or whatever.php, but they always get whatever.php in the browser, and this works even if whatever.htm doesn't exist!

Wednesday, January 11, 2012

PHP MYSQL before date descending order and after date ascending orderr

PHP MYSQL before date descending order and after date ascending order
(
SELECT *
FROM `usersexample`
WHERE date_col<=current_date
ORDER BY
date_col DESC
)
UNION (


SELECT *
FROM `usersexample`
WHERE date_col >=current_date
ORDER BY date_col ASC
)

Wednesday, December 28, 2011

PHP: Upload a Video to YouTube using Zend Gdata and YouTube API

How to upload video to you tube?
1)Download Zend  
2)Include Zend Gdata Libs Zend folder (i.e., library\Zend)

//include Zend Gdata Libs 
  require_once("Zend/Gdata/ClientLogin.php"); 
  require_once("Zend/Gdata/HttpClient.php"); 
  require_once("Zend/Gdata/YouTube.php");
  require_once("Zend/Gdata/App/MediaFileSource.php"); 
  require_once("Zend/Gdata/App/HttpException.php"); 
   require_once('Zend/Uri/Http.php'); 
     
    //yt account info 
    $yt_user = 'username'; //youtube username or gmail account 
    $yt_pw = 'password'; //account password 
    $yt_source = 'Name'; //name of application (can be anything) 
     
    //video path 
  // $video_url = 'http://example.com/YouTubeVideoApp/'.$target; 
   $video_url = '/target/upload/'.$name; 
      
     
    //yt dev key 
    $yt_api_key = '<your youtube developer key>'; //your youtube developer key 
     
    //login in to YT 
    $authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin'; 
    $httpClient = Zend_Gdata_ClientLogin::getHttpClient( 
                                              $username = $yt_user, 
                                              $password = $yt_pw, 
                                              $service = 'youtube', 
                                              $client = null, 
                                              $source = $yt_source, // a short string identifying your application 
                                              $loginToken = null, 
                                              $loginCaptcha = null, 
                                              $authenticationURL); 
     
    $yt = new Zend_Gdata_YouTube($httpClient, $yt_source, NULL, $yt_api_key); 
     
    $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry(); 
     
    $filesource = $yt->newMediaFileSource($video_url); 
    $filesource->setContentType('video/quicktime'); //make sure to set the proper content type. 
    $filesource->setSlug('mytestmovie.mov'); 
     
    $myVideoEntry->setMediaSource($filesource); 
     
    $myVideoEntry->setVideoTitle($title); 
    $myVideoEntry->setVideoDescription($desc); 
    // Note that category must be a valid YouTube category ! 
    $myVideoEntry->setVideoCategory('Entertainment'); 
     
    // Set keywords, note that this must be a comma separated string 
    // and that each keyword cannot contain whitespace 
    $myVideoEntry->SetVideoTags('Bridal, Bouquet, Designs'); 
     
    // Upload URI for the currently authenticated user 
     
    $uploadUrl = "http://uploads.gdata.youtube.com/feeds/users/$yt_user/uploads"; 
     
    // Try to upload the video, catching a Zend_Gdata_App_HttpException 
    // if availableor just a regular Zend_Gdata_App_Exception 
     
    try { 
        $newEntry = $yt->insertEntry($myVideoEntry, 
                                     $uploadUrl, 
                                     'Zend_Gdata_YouTube_VideoEntry'); 
    } catch (Zend_Gdata_App_HttpException $httpException) { 
        echo $httpException->getRawResponseBody(); 
    } catch (Zend_Gdata_App_Exception $e) { 
        echo $e->getMessage(); 
    } 
     
For more information see the YouTube Developer’s Guide 

Saturday, December 3, 2011

PHP interview questions and answers


PHP interview questions and answers

1. What does a special set of tags <?= and ?> do in PHP?
Ans:The output is displayed directly to the browser.
2. Who is the father of PHP ?
Ans:Rasmus Lerdorf is known as the father of PHP.
3. How i can get ip address?
Ans:We can use SERVER var $_SERVER['SERVER_ADDR'] 
and getenv("REMOTE_ADDR") functions to get the IP address.
4.How do you define a constant?
Ans:Via define() directive, like define ("MYCONSTANT", 500);
5.How do you pass a variable by value?
Ans:Put an ampersand in front of it, like $a = &$val.
6.Will comparison of string "49" and integer 50 work in PHP?
Ans:Yes, internally PHP will cast everything to the integer type,
so numbers 49 and 50 will be compared.
7. I am trying to assign a variable the value of 0123, but it keeps
coming up with a different number, what’s the problem?
Ans:PHP Interpreter treats numbers beginning with 0 as octal.
8.What’s the difference between htmlentities() and htmlspecialchars()?
 Ans:htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand. 
htmlentities translates all occurrences of character sequences that have different meaning in HTML.
9.In how many ways we can retrieve the data in the result set of MySQL using PHP?
Ans:We can do it by 4 Ways
1. mysql_fetch_row. , 2. mysql_fetch_array , 3. mysql_fetch_object
4. mysql_fetch_assoc
10.How can we create a database using PHP and MySQL?
Ans:We can create MySQL database with the use of mysql_create_db("Database Name") 
11.Can we use include ("xyz.PHP") two times in a PHP page "index.PHP"?
Ans:Yes we can use include("xyz.php") more than one time in any page. but it create a prob when xyz.php file contain some funtions declaration then error will come for already declared function in this file else not a prob like if you want to show same content two time in page then must incude it two time not a prob 
12.What is use of header() function in php ? 
Ans:The header() function sends a raw HTTP header to a client.We can use herder()
function for redirection of pages. It is important to notice that header() must
be called before any actual output is seen
13. Types of arrays in PHP?
Ans:In PHP, there are three kind of arrays:
1.Numeric array-->A numeric array stores each array element with a numeric index.
2.Associative array-->An associative array, each ID key is associated with a value.
3.Multidimensional array-->In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on.
14. What is difference between delete, truncate and drop in php myql?

delete table – will delete all records from the table only, but not an auto_increment. i.e,, the auto_increment counter does not get reset.
truncate table – will delete all records from the table and also rebuild the table, and resetting the auto_increment counts.
Drop the table- will drop the table structure as well as data
15. What is difference between echo and print?

echo is faster than print,
echo can execute more than 1 statements but print does not execute more than 1 statements
print can execute only a single statement.
echo — Output one or more strings
print — Output a string

16. What is difference between split and explode?
split--Splits a string into array by regular expression.
 ( This function has been DEPRECATED as of PHP 5.3.0. ) 

explode--Split a string by string , Returns an array of strings.


16. What is implode and join?


implode-- Join array elements with a string

join — Alias of implode()

join() and implode() are aliases of each other and therefore don't have any differences.

17. The Difference Between Cookies and Sessions
The main difference between cookies and sessions is that cookies are stored in the user's browser, and sessions are not. A cookie can keep information in the user's browser until deleted. Sessions work instead like a token allowing access and passing information while the user has their browser open. The problem with sessions is that when you close your browser you also lose the session.

18. Get the second highest salary in a MySQL employee table

1) SELECT * FROM emp WHERE sal= (SELECT MAX(sal) FROM emp WHERE sal< (SELECT MAX(sal) FROM emp))

2) SELECT max(sal) from emp where sal not in(select max(sal) from emp)

3) SELECT * FROM emp ORDER BY sal DESC LIMIT 1, 1

Thursday, December 1, 2011

DRUPAL interview questions and answers

DRUPAL interview questions and answers

What is Drupal?
Drupal is both content management system and blogging engine.
How to change drupal head icon in address bar / url link / navigation bar on top?
Just go to 'Administer » Site building » Themes >> Configure' and at the bottom of this page you will find a section called "Shortcut icon settings". There you can change the 'favicon'.

avi type
In order for you or your users to start uploading video using Video Module, you must add a Video as a content type on your site.

Go to Administer->Content management->ContentTypes.

Drupal Comments - With the default installation, only users that have logged in can access/post comments. 
This can be changed from Administer -> User management -> Permissions. The comments settings are self-explanatory. By default, registered users can post comments (they don't need to wait for moderator approvals).
If you want to let anonymous users post comments, go to Administer -> User management -> Permissions -> comment module.

What the difference is between the "page" node type and the "story" node type?
In terms of basic functionality, there is no difference.
->A page doesn't post author information, timestamps or comments by default.
->A story does post author information, timestamps or comments by default.

By default, a story entry is automatically featured on the site's initial home page, and provides the ability to post comments.

The Page option allows you to create a static page
What is the path to the Drupal user/admin login page?
The path of the Drupal user/admin login page is
http://yourdrupalsitename/user
or
http://yourdrupalsitename/?q=user 
What is the option makes Drupal emit "clean" URLs? (i.e. without ?q= in the URL).
Choose the enabled option under clean urls
Administer->Site configuration->Clean URLs.

What are the Drupal System requirements?
Disk space
-15 Megabytes
Web server
-Apache 1.3, Apache 2.x, or Microsoft IIS
Database server
-Drupal 6: MySQL 4.1 or higher, PostgreSQL 7.1,
-Drupal 7: MySQL 5.0.15 or higher with PDO, SQLite 3.3.7 or higher
PHP
Drupal 6: 5.2 recommended
Drupal 7: 5.3 recommended

Saturday, November 19, 2011

PHP interview questions and answers


PHP interview questions and answers

1. What does a special set of tags <?= and ?> do in PHP?
Ans:The output is displayed directly to the browser.
2. Who is the father of PHP ?
Ans:Rasmus Lerdorf is known as the father of PHP.
3. How i can get ip address?
Ans:We can use SERVER var $_SERVER['SERVER_ADDR'] 
and getenv("REMOTE_ADDR") functions to get the IP address.
4.How do you define a constant?
Ans:Via define() directive, like define ("MYCONSTANT", 500);
5.How do you pass a variable by value?
Ans:Put an ampersand in front of it, like $a = &$val.
6.Will comparison of string "49" and integer 50 work in PHP?
Ans:Yes, internally PHP will cast everything to the integer type,
so numbers 49 and 50 will be compared.
7. I am trying to assign a variable the value of 0123, but it keeps
coming up with a different number, what’s the problem?
Ans:PHP Interpreter treats numbers beginning with 0 as octal.
8.What’s the difference between htmlentities() and htmlspecialchars()?
 Ans:htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand. 
htmlentities translates all occurrences of character sequences that have different meaning in HTML.
9.In how many ways we can retrieve the data in the result set of MySQL using PHP?
Ans:We can do it by 4 Ways
1. mysql_fetch_row. , 2. mysql_fetch_array , 3. mysql_fetch_object
4. mysql_fetch_assoc
10.How can we create a database using PHP and MySQL?
Ans:We can create MySQL database with the use of mysql_create_db("Database Name") 
11.Can we use include ("xyz.PHP") two times in a PHP page "index.PHP"?
Ans:Yes we can use include("xyz.php") more than one time in any page. but it create a prob when xyz.php file contain some funtions declaration then error will come for already declared function in this file else not a prob like if you want to show same content two time in page then must incude it two time not a prob 
12.What is use of header() function in php ? 
Ans:The header() function sends a raw HTTP header to a client.We can use herder()
function for redirection of pages. It is important to notice that header() must
be called before any actual output is seen
13. Types of arrays in PHP?
Ans:In PHP, there are three kind of arrays:
1.Numeric array-->A numeric array stores each array element with a numeric index.
2.Associative array-->An associative array, each ID key is associated with a value.
3.Multidimensional array-->In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on.







Friday, November 18, 2011

Ago date or time - Time ago/Day ago


Ago date or time - Time ago/Day ago 

"year+month+day+time ago"  PHP function

Function to format the comment post times in the ever trendy "time ago" style... such as; posted 6 months 3 weeks ago;
<?php
function time_ago($date,$granularity=2) {
    $date = strtotime($date);
    $difference = time() - $date;
    $periods = array('decade' => 315360000,
        'year' => 31536000,
        'month' => 2628000,
        'week' => 604800,
        'day' => 86400,
        'hour' => 3600,
        'minute' => 60,
        'second' => 1);
    if ($difference < 5) { // less than 5 seconds ago, let's say "just now"
        $retval = "posted just now";
        return $retval;
    } else {                           
        foreach ($periods as $key => $value) {
            if ($difference >= $value) {
                $time = floor($difference/$value);
                $difference %= $value;
                $retval .= ($retval ? ' ' : '').$time.' ';
                $retval .= (($time > 1) ? $key.'s' : $key);
                $granularity--;
            }
            if ($granularity == '0') { break; }
        }
        return ' posted '.$retval.' ago';     
    }
}


//call a function here
echo $date = time_ago('2011-04-22 16:59:06');?>

Thursday, November 10, 2011

What is a Favicon?

What is a Favicon?

A favicon (short for "favorites icon" and also known as a page icon), is an icon associated with a particular website or webpage that is displayed in the browser address bar next to a site's URL. 

Copy and paste the following code to the <head> section of your webpages:

<link rel="shortcut icon" href="/favicon.ico" >