What difference between require() and require_once().

December 19, 2009 | Filed Under PHP | 1 Comment

Require()

The  Require() is  used to include a file, It create fatal  error if file not found and  terminate  script.

require_once()

The require_once() to require() except PHP will check if the file has already been included, and  if so, tricor online not include (require) it again.

Article written by admin

What difference between include () and include_once()?

December 19, 2009 | Filed Under PHP | Comments Off

include ()

The include ()  is  used to include a file, It create warning  if file not found and  execute   script.

include_once()

The include _once() statement include () except PHP will check if the file has already been included, and if so, not include (include) it again.

Article written by admin

How many ways can includes files in php.

December 19, 2009 | Filed Under PHP | Comments Off

There are  4 methods to includes  files

require()

require_once()

include()

include_once()

Article written by admin

Superglobal variables in php.

December 19, 2009 | Filed Under PHP | Comments Off

There are  number of superglobal variables in php

  • $GLOBALS
  • $_SERVER
  • $_GET
  • $_POST
  • $_FILES
  • $_COOKIE
  • $_SESSION
  • $_REQUEST
  • $_ENV
Article written by admin

PHP cURL functions tutorial

December 19, 2009 | Filed Under PHP | 1 Comment

cURL is a library which allows you to connect and communicate to many different types of servers with many different types of protocols. Using cURL you can:

  • Implement payment gateways’ payment notification scripts.
  • Download and upload files  from remote servers.
  • Login to other websites and access members only sections.

PHP cURL library is definitely the odd man out. Unlike other PHP libraries where a whole plethora of functions is made available, PHP cURL wraps up a major parts of its functionality in just four functions.

A typical PHP cURL usage follows the following sequence of steps.

curl_init – Initializes the session and returns a cURL handle which can be passed to other cURL functions.

curl_opt – This is the main work horse of cURL library. This function is called multiple times and specifies what we want the cURL library to do.

curl_exec – Executes a cURL session.

curl_close – Closes the current cURL session.

Below are some examples which should make the working of cURL more clearer.

The below piece of PHP code uses cURL to download Google’s RSS feed.

<?php
/**
* Initialize the cURL session
*/

$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/

curl_setopt($ch, CURLOPT_URL,
‘http://news.google.com/news?hl=en&topic=t&output=rss’);
/**
* Ask cURL to return the contents in a variable
* instead of simply echoing them to the browser.
*/

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
/**
* Execute the cURL session
*/

$contents = curl_exec ($ch);
/**
* Close cURL session
*/

curl_close ($ch);
?>

As you can see, curl_setopt is the pivot around which the main cURL functionality revolves. cURL functioning is controlled by way of passing predefined options and values to this function.

The above code uses two such options.

  • CURLOPT_URL: Use it  to specify the URL which you want to process. This could be the URL of the file you want to download or it could be the URL of the script to which you want to post some data.
  • CURLOPT_RETURNTRANSFER: Setting this option to 1 will cause the curl_exec function to return the contents instead of echoing them to the browser.
Article written by tabrez

What is Type Juggling?

December 19, 2009 | Filed Under PHP | Comments Off

Juggling means

throwing and catching several objects simultaneously.

Type Juggling in php  means automatically type conversion.

That is to say, if a string value is assigned to variable $var$var becomes a string. If an integer  value is assigned to $var, it becomes an integer.

Please see Example.

<?php
$var = "0";// $var is string (ASCII 48)
$var += 10; // $var is now an integer (10)
$var = $foo+ 1.5; // $var is now a float (11.5)
$var = 5 + "10 Little hots"; // $var  is integer (15)
$ var = 5 + "10 Small hots"; // $var  is integer (15)
?>

$var variable comes many times in different data type.

Often it became interger, float.

This is Type Juggling in php.

Thank you

Article written by admin

How many data type are present in PHP.

December 18, 2009 | Filed Under PHP | Comments Off

PHP supports 8  data  types.

  • boolean
  • integer
  • float (floating-point number, aka double)
  • string
  • array
  • object
  • resource
  • NULL

Explaination:

4 scalar types:

boolean

<?php

$var = True; // assign the value TRUE to $foo
?>

integer

<?php
$var = 123; // decimal number
$var = -122; // a negative number
$var = 0111; // octal number
$var = 0x1B; // hexadecimal number

?>

float (floating-point number, aka double)

<?php
$var = 1.234;
$var= 1.2e3;
$var = 7E-10;
?>

string

<?php
$string =”Hello World”;  // Assign Hello World into $string

?>

2 compound types:

array

<?php
$array = array(“first”=>”Hello”,”second”=>”World”);

echo $array[‘first’];

echo $array[‘second];

?>

object

<?php

Class Interview

{

Function php()

{

Echo “What  is php”;

}

}

$obj = new Interview(); // $obj is object , you can also take different name   like  $object,$interview

Echo $obj-> php();

?>

3 compound types:

resource

NULL

<?php
$variable = NULL;
?>

Note:  PHP does not require to define variable in in any specific data type. Like  integer,float,string etc, like C,C++.

PHP  support   automatic type conversion .
For More Detail see Type Juggling articles.

Thank you

Article written by admin

© PHPInterviewQuestion.com 2009 - 2012

eXTReMe Tracker