Breaking News
Loading...
Monday 30 July 2012

PHP Interview Question and Answers

04:38
31. How to store the uploaded file to the final location?

move_uploaded_file( string filename, string destination)
32. What type of headers have to be added in the mail function to attach a file?

$boundary = '--' . md5( uniqid ( rand() ) );
$headers = "From: \"Me\"\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
?>

33. How can we find the number of rows in a result set using php?

$result = mysql_query($any_valid_sql, $database_link);
$num_rows = mysql_num_rows($result);
echo “$num_rows rows found”;
?>

34. How can we know the number of days between two given dates using php?

$tomorrow = mktime(0, 0, 0, date("m") , date("d")+1, date("Y"));
$lastmonth = mktime(0, 0, 0, date("m")-1, date("d"), date("Y"));
echo ($tomorrow-$lastmonth)/86400;
?>

35. How to open a file?

$file = fopen("file.txt","r");
?>

36. How many open modes available when a file open in PHP?

r , r+ , w , w+ , a , a+ , x , x+

37. Explain the types of string comparision function in PHP?

FunctionDescriptions
1.strcmp()Compares two strings (case sensitive)
2.strcasecmp()Compares two strings (not case sensitive)
3.strnatcmp(str1, str2);Compares two strings in ASCII order, but any numbers are compared numerically
4.strnatcasecmp(str1,str2);Compares two strings in ASCII order, case insensitive, numbers as numbers
5.strncasecomp()Compares two strings (not case sensitive) and allows you to specify how many characters to compare
6.strspn()Compares a string against characters represented by a mask
7.strcspn()Compares a string that contains characters not in the mask

38. Explain soundex() and metaphone()?

soundex()
The soundex() function calculates the soundex key of a string. A soundex key is a four character long alphanumeric string that represent English pronunciation of a word. he soundex() function can be used for spelling applications.

<?php
$str = "hello";
echo soundex($str);
?>

metaphone()
The metaphone() function calculates the metaphone key of a string. A metaphone key represents how a string sounds if said by an English speaking person. The metaphone() function can be used for spelling applications.

<?php

echo metaphone("world");
?>

39. Explain the types of functions for Splitting String?

FunctionDescriptions
1.split()Splits a string into an array by using a regular expression as the delimiter.
2.spliti()Splits a string into an array by a regular expression and is case insensitive.
3.str_split()Converts a string into an array where the size of the elements can be specified
4.preg_split()Splits up a string by a Perl compatible regular expression and returns an array of substrings
5.explode()Splits up a string by another string (not a regular expression) and returns an array
6.implode()Joins array elements together by a string and returns a string


40. Explain Whitespace Characters.

Whitespace CharacterASCII Value(Decimal/Hex)Descriptions
" "32 (0x20))An ordinary space
"\t"9(0x0)A tab.
"\n"10(0x0A)A newline (line feed).
"\r"13(0x0D))A carriage return.
"\0"0(0x00))The NULL-byte.
"\x0B"11(0x0B))A vertical tab.


<< Next 1 2 3 4 5 Previous>>

Share This :
Tags:

0 comments:

Post a Comment

 
Toggle Footer