Showing posts with label PHP interview questions. Show all posts
Showing posts with label PHP interview questions. Show all posts

Sunday, November 6, 2011

What is the difference between urlencode and urldecode ?

The difference between urlencode and urldecode is
URLencode is used to encode a string to be passed through URL to a web page. URLencode replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits.

Use this link to get more stuff on Urlencode http://www.w3schools.com/tags/ref_urlencode.asp


URLdecode is used to decode the encoded URL string . Decodes any %## encoding in the given string

What is the difference between array_slice() and array_splice()?

The difference between array_slice() and array_splice()

array_splice() is used to remove some elements from an array and replace with specified elements.
Below are some code examples:
<?php
$input = array("red", "green", "blue", "yellow");
array_splice($input, 2);
// $input is now array("red", "green")

$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, -1);
// $input is now array("red", "yellow")

$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, count($input), "orange");
// $input is now array("red", "orange")

$input = array("red", "green", "blue", "yellow");
array_splice($input, -1, 1, array("black", "maroon"));
// $input is now array("red", "green",
// "blue", "black", "maroon")

$input = array("red", "green", "blue", "yellow");
array_splice($input, 3, 0, "purple");
// $input is now array("red", "green",
// "blue", "purple", "yellow");
?>

 array_slice() is used to extract a slice of the array. Below are some example codes:

<?php
$input = array("a", "b", "c", "d", "e");

$output = array_slice($input, 2); // returns "c", "d", and "e"
$output = array_slice($input, -2, 1); // returns "d"
$output = array_slice($input, 0, 3); // returns "a", "b", and "c"

// note the differences in the array keys
print_r(array_slice($input, 2, -1));
print_r(array_slice($input, 2, -1, true));
?>
The above example will output:


Array
(
[0] => c
[1] => d
)
Array
(
[2] => c
[3] => d
)






What is the difference between unlink and unset ?

The difference between unlink and unset is given below:

Unlink is used to delete a file for a given path.
where as
Unset is used to delete a value of a variable.

What is Codeigniter?

Codeigniter is a PHP framework and follows MVC architecture. It is an open source. It provides a great flexibility to PHP coders with its built in functions. This framework is used to develop full featured web applications. This framework is easy to learn and there are no coding restrictions to follow, we can use core PHP also. There is no need of learning a new template language for this framework. Below image illustrates the flow of logic in the codeigniter system.

Follow this URL to know more about codeigniter http://codeigniter.com/
Download the latest version here http://codeigniter.com/download.php
Follow this link to view User guide http://codeigniter.com/user_guide/


Saturday, November 5, 2011

What is Joomla in PHP?

Joomla is a Content Management System. It is an Open Source CMS framework programmed with PHP. The main advantahe of CMS is, there is no need of making your websites from scratch. Many functionalities like : forum, calendar, mail etc. are built in - as extensions.

Joomla! is one of the most powerful and an award-winning Open Source Content Management System (CMS) that will help you build everything from simple websites to complex corporate applications. Joomla! is easy to install, simple to manage. The MVC architecture is implemented in Joomla latest versions. It is a rapid action development tool of websites.

To know more about joomla visit the website www.joomla.org

To download joomla go to www.joomla.org/download

What is the difference between "mysql_fetch_array" and "mysql_fetch_object"

The difference between "mysql_fetch_array" and "mysql_fetch_object" is
"mysql_fetch_array" function will take the result set as input and returns an associative array with data fetched from database table row. Where as,
"mysql_fetch_object" function will take the result set as input and returns an object with data fetched from database table row.





How many ways you can delete a session variable ?

Below are some possibilities for deleting a PHP session,

  1. By using session_destroy() function
  2. By deleting browsers temporary files.
  3. By closing the browser
  4. Security firewalls may terminate the session varibles


How will you create a bi-lingual site (multiple languages) ?

By using define constant construct we can create bi-lingual sites. We will create a PHP file with define constants  for each language and will include the file in our main pages where the actual content is displayed

Monday, October 24, 2011

How do you upload files in PHP ?

We can upload files by using move_uploaded_file(). There are two parameters for the move_uploaded_file function. One is to specify uploaded file details and other is to specify new file details to be created.
The steps to follow are
    1) Include enctype="multipart/formdata" in the form tag.
    2) Using method post is recommended.
    3) We use $_FILES super global array to get the uploaded file details.
    4) By using $_FILES we can validate the file for size, file type.