Getting good with php

Page 112

112

Chapter 5

Example 5-13 echo date("F j, Y", 1234567890, "something else"); echo date("F j, Y", 1234567890);

Here we’re using the date function. This function takes a format string (where “F” stands for the month name, etc.) and an optional timestamp. However, the function doesn’t take a third parameter. When we give it a third, we get a warning:

Notice that the second line above still executes, because warnings don’t stop the execution of the file.

Notices Notices are a step down from warnings; these are for things that might indicate an error (or might not). Trying to use a variable or array item that doesn’t exist will cause a notice. Also, using a deprecated function will cause a notice (although, it’s not labeled that way): Example 5-14 $a = split(" ", "a b c");print_r($a); # Array ( [0] => a [1] => b [2] => c )

Here we’re using the split method, which has been deprecated; this means that it’s not recommended to use this function, it’s been replaced with something better, and it will probably be taken out of future versions of PHP. What it does is split the second parameter (a string) by the regular expression pattern or string given as the first parameter. If you run the above code you’ll see that we get a “Deprecated” message.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.