Friday, 13 November 2015

PHP Difficult Interview Questions and Answers

PHP Difficult Interview Questions and Answers


Question: How to check a variable is NULL OR empty string?
var_dump($variableName);

Also for compare you can use === to compare data type.


Question: How can I execute an anonymous function?
call_user_func(function() { echo 'anonymous function called.'; });



Question: How can I measure the speed of code written in PHP?
$startTime= microtime(true);
/** Write here you code to check **/
/** Write here you code to check **/
$endTime= microtime(true);
echo 'Time Taken to executre the code:'.$endTime-$startTime;



Question: Which PHP Extension help to debug the code?
Xdebug


Question: How to get Yesterday date?
date("F j, Y", strtotime( '-1 days' ) ); //November 11, 2015



Question: How to set HTTP header to UTF-8 using?
Add following at the top of page.
header('Content-Type: text/html; charset=utf-8');



Question: How to get first 20 characters from string?
echo substr('Web Technology Experts Notes',0,20);



Question: How to get last date of month of given date?
$date = "2015-11-23";
echo date("Y-m-t", strtotime($date));



Question: How do I check with PHP if file exists?
$filename = "/folder/filename.php";
if (file_exists($filename)) {    
    echo "The file $filename exists.";    
} else {
    echo "The file $filename does not exists.";
}



Question: How to remove non-alphanumeric characters ?
echo preg_replace("/[^A-Za-z0-9 ]/", '', 'web technology experts notes @2015 '); //web technology experts notes 2015



Question: How do I replace all line breaks (\n\r) in a string with
tags?

echo str_replace(array('\r','\n','\r\n'),'
','Hello \n Web technology');



Question: How do I format a number to a dollar amount in PHP? Give Example?
Use money_format
echo money_format('$%i', 6.6); // echos '$3.40' //echos $6.60



Question: How to prevent Browser cache for php site?
Add following code at the top of web page.
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");



Question: How do i get the current script file name?
echo __FILE__; //htdocs/project/index.php



Question: How to add key/value in existing array?
$arrayname['keyname'] = 'new value';



Tuesday, 27 October 2015

SVN interview questions and answers

SVN interview questions and answers


Question: What is SVN?
Subversion is an open source control system which is used to trace all the changes made to your source code.


Question: List out what all things should be stored in SVN repository?
  1. Source Code
  2. MySQL Queries
  3. Database Updates
  4. Project regarding important files
  5. Product Documents
  6. Minutes of Metting and Imp Email


Question: How to add SVN file?
svn add filename.php


Question: How to add SVN folder?
svn add foldername


Question: How to get Updates from SVN Repo
svn update


Question: How to delete file from SVN Repo?
svn delete filename


Question: How to get SVN Info?
svn info


Question: How to get SVN Log for a file?
svn log testFile.php


Question: How to check for modifications?
svn status -v PATH


Question: Difference between SVN commit and SVN update?
SVN commit:: Push (upload) the local changes to Repository.
SVN Update:: Get (download) the Repository changes files to local system.


Question: What is use of Revert in SVN?
Revert your local changes.
It have two types
1) Local Revert: It will delete all changes from files which you made after updates and before commit.
2) Repo Revert: Upload the changes to previous Repo.


Question: List out what is the best practices for SVN?
  1. Work from your own local work-space
  2. Commit small autonomous changes
  3. Use comment
  4. Validate the files you are committing, you actually changed
  5. Take Update before commit to the Repo.



Question: How to apply a patch in SVN ?
First we need to "Create Patch" by making changes and generating the .diff file. Then this .diff file can be applied to the new Code base using "Apply Patch".