How do you remove the last letter from a string?

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?

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?

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()?

htmlspecialchars only takes care of <, >, single quote ‘, double quote ” and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.

With a heredoc syntax, do I get variable substitution inside the heredoc contents? -

Yes.

What is the difference between characters ?23 and x23?

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?

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?

<?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?

100, it’s a reference to existing variable.

How do I find out the number of parameters passed into function?

func_num_args() function returns the number of parameters passed in.