PHP Interview QuestionsWe all know that PHP skills are in demand, and that's part of the reason why we learn and use PHP right? However, before getting that coveted job, there is the small matter of the interview to get through. Here we list some common PHP interview questions, and possible answers. If you encounter a particular question then you can contact us and we'll add it to the page.
- How do you access data submitted through GET or POST from a form?
- Write a simple program to get a row of information from a database?
- What is the difference between include and require?
- How do you remove the last letter from a string?
- What do you need to use the image functions in PHP?
To access data use $_GET and $_POST respectively. For instance if a form is submitted with a field named 'email' through post, then this becomes available as $_POST[email].
With GET, the information is posted in the URL so this is useful if you want to store or bookmark a URL that relies on parameterised data. However GET is less secure, and also has strict limits on the amount of data that can be sent.
$myrow = mysql_query("SELECT name,email FROM visitors ORDER by name LIMIT 1");
$data = mysql_fetch_row($myrow);
$name = $data; $email = $data;
echo "A row from the database is name $name and email $email";
If you require a file and it cannot be found, the script will terminate with a fatal error. If you use include then you will get an error but the script will continue to execute. Therefore when the information you wish to reference from another file is essential to the correct running of a page, use require.
There are many ways to do this. An interviewer will be looking for you to use a compact method. Here is probably the simplest method:
$data = "One too many letterss"; $newdata = substr($data,0,-1);// now 'one too many letters'
You need to have access to the GD Library in order to use the image functions in PHP.