Question 6 :
What's the output of the ucwords function in this example?
$formatted = ucwords("TECHPREPARATIONS IS COLLECTION OF INTERVIEW QUESTIONS"); print $formatted;
What will be printed is TECHPREPARATIONS IS COLLECTION OF INTERVIEW QUESTIONS.
ucwords() makes every first letter of every word capital, but it does not lower-case anything else. To avoid this, and get a properly formatted string, it's worth using strtolower() first.
Question 7 :
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.
Question 8 :
How can we extract string "abc.com" from a string "mailto:email@example.com?subject=Feedback" using regular expression of PHP?
$text = "mailto:firstname.lastname@example.org?subject=Feedback"; preg_match('|.*@([^?]*)|', $text, $output); echo $output;
Note that the second index of $output, $output, gives the match, not the first one, $output.
Question 9 :
So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?
Crypto usage in PHP is simple, but that doesn't mean it's free. First off, depending on the data that you're encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.
Question 10 :
How can we destroy the session, how can we unset the variable of a session?
session_unregister() - Unregister a global variable from the current session
session_unset() - Free all session variables