How do you remove the last letter from a string?
Dec 8th
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’
What’s the difference between md5(), crc32() and sha1() crypto on PHP?
Dec 8th
The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.
How do you access data submitted through GET or POST from a form?
Dec 8th
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.
What’s the difference between htmlentities() and htmlspecialchars()?
Dec 8th
htmlspecialchars only takes care of <, >, single quote ‘, double quote ” and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.
What is the difference between characters ?23 and x23?
Dec 8th
The first one is octal 23,the second is hex 23.
How come the code works, but doesn’t for two-dimensional array of mine?
Dec 8th
Any time you have an array with more than one dimension, complex parsing syntax is required. print “Contents: {$arr[1][2]}” would’ve worked.
Why doesn’t the following code print the newline properly?
Dec 8th
<?php
$str = ‘Hello, there.nHow are you?nThanks for visiting TechInterviews’;
print $str;
?>
Because inside the single quotes the n character is not interpreted as newline, just as a sequence of two characters – and n.
If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b?
Dec 8th
100, it’s a reference to existing variable.
How do I find out the number of parameters passed into function?
Dec 8th
func_num_args() function returns the number of parameters passed in.