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.

Wednesday, October 19, 2011

How will you redirect to a page without header function?

By using Javascript we can redirect the page to another page. And also there are htaccess redirection techniques.

What is a common error caused with header function?

headers already sent output started at some x line is the error. This error occurs when there is an out put generated before the header function.

How do you know whether the headers are sent or not?

We have a function headers_sent(). This function is used to check whether the headers are already sent.

What is the difference between method get and method post?

The first difference is, method get is faster in performance than post. Because, by using post method the data posted is encrypted to cipher data and sent to the server. Where in get the encryption does not happens and it is faster.
    Get method can carry limited amount of data and it is less than post method.
    Post method is secure than get as the data submitted is not visible to the real world. Where as in the get method some one may see the data submitted in the URL bar.
    Using post method We can submit the data to the server only with the help of an HTML form. Where as a get method can send the data to server with a form and also with a HTML hyperlink.

What is difference between include() function and require() function?

Both the functions are used to include a PHP file in other PHP file. Generally if we have a block of source code usefull in multiple instances, then we place the block of source code in one file and will include the file in other files. The difference between include() and require() function are as follows:
    (i) If the file path mentioned with the include function is not found then it shows a warning message and continues the execution of the script. Where as require function results a fatal error and stops the execution of the script.
    (ii) The second difference is include function is faster in execution than require function. Because with the require function the parser will check whether the file exists or not. Where as the include function does not bothere about the file is there or not.

Monday, October 10, 2011

How many types of comments are there in PHP?

There are two types of comments in PHP. They are
  1. One Line comments (// or #)
  2. Multiple Line comments (/* */)
The "one-line" comment styles only comment to the end of the line or the current block of PHP code, whichever comes first.
Eg:
      
     <?
      // echo 'Your code upto end of the line'; 
     ?>
     <?
     # echo 'Your code upto end of the line';  
     ?> 

Multiple Line comments (/* */) are used to comment a large block of PHP code.
Ex: <?
 /*
    echo 'This is a test';
    echo 'This is a test line2';
       echo 'This is a test line 3';
 */
?>





Wednesday, October 5, 2011

What is the difference between displaying a string in single quotes and double quotes in PHP?

1) With Single Quotes the performance is faster than double quotes because the PHP parser does not checks for any variables or special characters. Whatever is there it will display that.
2) With double quotes the parser will search for the variables embedded in the string.
3) Performance wise it is always better to use single quotes. And we can use the concatenation between the strings and the variables.
4) Double quotes recognizes the new line charactes like '\n','\t' etc.., where as single quotes does not.

Top 10 PHP MVC frameworks

A good framework is easy to learn, simple to use, intuitive to work with, easy to extend or to modify, rapid to build (maintain) applications with and of course stable.

Having said that, here is my top 10 PHP MVC Frameworks:

10- Ambivalence: A Java-Maverick Port
9- WACT: Web Application Component Toolkit
8- Achievo: A good RAD framework
7- Phrame: A Java-Struts port
6- Studs: A Java-Struts port to PHP
5- Prado: The winner of Zend coding contest
4- PHPOnTrax: a Rails port - PHP5 Only
3- CakePHP: Inspired by Rails PHP4/5
2- Mojavi: The first MVC framework I fell in love with

and the winner is:

1- Symfony: Based on Mojavi and inspired by Rails

This list is based on my personal tests and use. I have tested and played with many others, but I think these are the best frameworks out there.
- The first framework I fell in love with was Mojavi because of its elegant way to implement the MVC model.
- Symfony corrected some problems in Mojavi and improved it by taking the good sides of RubyOnRails and Propel.
- CakePHP is very promising, the only problem - really, I don't know if it is a problem - is: the development process is very slow.

Redirecting a Web Page Using a 301 Redirect with HTACCESS file

Below is the steps involved in redirecting a web page usinh HTACCESS file.
Know about .htaccess file
When a visitor/spider requests a web page, your web serverchecks for a .htaccess file. The .htaccess file containsspecific instructions for certain requests, includingsecurity, redirection issues and how to handle certainerrors.
Know about 301 redirect
301 redirect is the best method to preserve your currentsearch engine rankings when redirecting web pages or a website. The code "301" is interpreted as "moved permanently".After the code, the URL of the missing or renamed page isnoted, followed by a space, then followed by the newlocation or file name. You implement the 301 redirect bycreating a .htaccess file.
How to implement the 301 Redirect
1. To create a .htaccess file, open notepad, name and savethe file as .htaccess (there is no extension).
2. If you already have a .htaccess file on your server,download it to your desktop for editing.
3. Place this code in your .htaccess file:redirect 301 /old/old.htm http://www.you.com/new.htm
4. If the .htaccess file already has lines of code in it,skip a line, then add the above code.
5. Save the .htaccess file
6. Upload this file to the root folder of your server.
7. Test it by typing in the old address to the page you'vechanged. You should be immediately taken to the newlocation.
Notes: Don't add "http://www" to the first part of thestatement - place the path from the top level of your siteto the page. Also ensure that you leave a single spacebetween these elements:
          redirect 301 (the instruction that the page has moved)
          /old/old.htm (the original folder path and file name)
          http://www.you.com/new.htm (new path and file name)
When the search engines spider your site again they willfollow the rule you have created in your .htaccess file.The search engine spider doesn't actually read the .htaccess file, but recognizes the response from the server as valid.
During the next update, the old file name and path will bedropped and replaced with the new one. Sometimes you maysee alternating old/new file names during the transitionperiod, plus some fluctuations in rankings. According toGoogle it will take 6-8 weeks to see the changes reflectedon your pages.
Other ways to implement the 301 redirect:
1. To redirect ALL files on your domain use this in your.htaccess file if you are on a unix web server:
          redirectMatch 301 ^(.*)$ http://www.domain.com
          redirectMatch permanent ^(.*)$ http://www.domain.com
You can also use one of these in your .htaccess file:
          redirect 301 /index.html http://www.domain.com/index.html
          redirect permanent /index.html http://www.domain.com/index.html
          redirectpermanent /index.html http://www.domain.com/index.html
This will redirect "index.html" to another domain using a301-Moved permanently redirect.
2. If you need to redirect http://mysite.com tohttp://www.mysite.com and you've got mod_rewrite enabled onyour server you can put this in your .htaccess file:
          Options +FollowSymLinks
          RewriteEngine on
          RewriteCond %{HTTP_HOST} ^example\.com
          RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
or this:
          Options +FollowSymLinks
          RewriteEngine
          OnRewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
          RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
Tip: Use your full URL (ie http://www.domain.com) whenobtaining incoming links to your site. Also use your fullURL for the internal linking of your site.
3. If you want to redirect your .htm pages to .php pagesandd you've got mod_rewrite enabled on your server you canput this in your .htaccess file:
          RewriteEngine on
          RewriteBase /
          RewriteRule (.*).htm$ /$1.php
4. If you wish to redirect your .html or .htm pages to.shtml pages because you are using Server Side Includes(SSI) add this code to your .htaccess file:
          AddType text/html .shtml
          AddHandler server-parsed .shtml .html .htm
Options Indexes FollowSymLinks Includes
DirectoryIndex index.shtml index.html