[ Pobierz całość w formacie PDF ]
.For instance, the format y-m-d returns 06-08-10, and M.d.Y returns Aug.10.2006.Table 1-6 lists some of the symbols that youcan use in the format string.(For a complete list of symbols, see the docu-mentation at www.php.net/manual/en/function.date.php.) The partsof the date can be separated by a hyphen (-), a dot (.), a forward slash (/),or a space.Table 1-6 Date Format SymbolsSymbol Meaning ExampleF Month in text, not abbreviated JanuaryM Month in text, abbreviated Janm Month in numbers with leading zeros 02, 12n Month in numbers without leading zeros 1, 12d Day of the month; two digits with leading zeros 01, 14j Day of the month without leading zeros 3, 30l Day of the week in text, not abbreviated FridayD Day of the week in text, abbreviated Friw Day of the week in numbers From 0 (Sunday) to6 (Saturday)Y Year in four digits 2002y Year in two digits 02g Hour between 0 and 12 without leading zeros 2, 10G Hour between 0 and 24 without leading zeros 2, 15h Hour between 0 and 12 with leading zeros 01, 10H Hour between 0 and 24 with leading zeros 00, 23i Minutes 00, 59s Seconds 00, 59a am or pm in lowercase am, pmA AM or PM in uppercase AM, PM11_167779 bk02ch01.qxp 12/17/07 8:08 PM Page 141141Using Dates and TimesStoring a timestamp in a variableYou can assign a timestamp with the current date and time to a variable withthe following statements:$today = time();Another way to store a current timestamp is with the statement$today = strtotime( today );You can store specific timestamps by using strtotimewith various key-words and abbreviations that are similar to English.For instance, you can Book IIChapter 1create a timestamp for January 15, 2006, as follows:$importantDate = strtotime( January 15 2006 );strtotimerecognizes the following words and abbreviations:&' Month names: Twelve month names and abbreviations&' Days of the week: Seven days and some abbreviations&' Time units:year, month, fortnight, week, day, hour, minute,second, am, pm&' Some useful English words:ago, now, last, next, this, tomorrow,yesterday&' Plus and minus:+or -&' All numbers&' Time zones: For example, gmt(Greenwich Mean Time), pdt(PacificDaylight Time), and akst(Alaska Standard Time)You can combine the words and abbreviations in a wide variety of ways.Thefollowing statements are all valid:$importantDate = strtotime( tomorrow ); #24 hours from now$importantDate = strtotime( now + 24 hours );$importantDate = strtotime( last saturday );$importantDate = strtotime( 8pm + 3 days );$importantDate = strtotime( 2 weeks ago ); # current time$importantDate = strtotime( next year gmt );$importantDate = strtotime( this 4am ); # 4 AM todayIf you wanted to know how long ago $importantDatewas, you could sub-tract it from $today.For instance:$timeSpan = $today - $importantDate;PHP Basics11_167779 bk02ch01.qxp 12/17/07 8:08 PM Page 142142 Understanding PHP Error MessagesThis gives you the number of seconds between the important date andtoday.Or use the statement$timeSpan =(($today - $importantDate)/60)/60to find out the number of hours since the important date.Understanding PHP Error MessagesPHP tries to be helpful when problems arise.It provides different types oferror messages and warnings with as much information as possible.Types of PHP error messagesPHP can display five types of messages.Each type of message displays thename of the file where the error was encountered and the line number wherePHP encountered the problem.Different error types provide additional infor-mation in the error message.The types of messages are&' Parse error: A parse error is a syntax error that PHP finds when it scansthe script before executing it.&' Fatal error: PHP has encountered a serious error that stops the execu-tion of the script.&' Warning: PHP sees a problem, but the problem isn t serious enough toprevent the script from running.&' Notice: PHP sees a condition that might be an error or might be per-fectly okay.&' Strict: Strict messages, added in PHP 5, warn about coding standards.You get strict messages when you use language that is poor coding prac-tice or has been replaced by better code.We recommend writing your PHP scripts with an editor that uses line num-bers.If your editor doesn t let you specify which line you want to go to, youhave to count the lines manually from the top of the file every time that youreceive an error message.You can find information about many editors,including descriptions and reviews, at www.php-editors.com.Understanding parse errorsBefore starting to run a script, PHP scans the script for syntax errors.Whenit encounters an error, it displays a parse error message
[ Pobierz całość w formacie PDF ]