Documente Academic
Documente Profesional
Documente Cultură
$now = getdate();
?>
Formatting Timestamps
// get time
// get date and time// result: "Monday, 30 October 2006, 12:38:26 PM" (example)
// result: "2006-10-30T12:38:26+00:00"
?>
echo ($ts === -1) ? "Invalid string" : date("l, d F Y h:i:s A", $ts);
?>
<?php
? true : false;
return $ret;}
// result: "Is a leap year"echo testLeapYear(2004) ? "Is a leap year" : "Is not a leap
year";
// result: "Is not a leap year"echo testLeapYear(2001) ? "Is a leap year" : "Is not a leap
year";
?>
$ts = mktime(0,0,0,3,1,2005);
// find number of days in month
// result: 31
?>
<?php
// result: 61
?>
<?php
$ts = mktime(0,0,0,6,4,2008);
// result: "Wednesday"
?>
<?php
?>
<?php
// get quarter
// result: 2
?>
<?php
$ts = mktime(4,30,0,2,2,2005);
?>
<?php
// performs conversion
?>
<?php
TIMESTAMP/DATETIME
format,use the
date()
FROM_UNIXTIME()
function:
∝
mysql_error());$row = mysql_fetch_object($result);mysql_close($connection);// result:
"2007-07-02 22:04:32"echo $row->tsField;?>
Comparing Dates
Truncating Strings
// truncate if necessary
} else {
return $str;}}
there are different languages that can be used onthe server as well.";
echo truncateString($str);
?>
// define string
$chunkSize = 11;
// result: [0] = The mice ju [1] = mped over t [2] = he cat, gig
print_r($chunkedArr);
?>
<?php
// compare strings
?>
Parsing Comma-Separated Lists
<?php
?>
Parsing URLs
<?php
article.php?id=79 &page=2";
$data = parse_url($url);
?>
<?php
// define string$text = "Fans of the 1980 group will have little trouble recognizing ∝
since these two elements are present in almost every song on the ∝
album; however, the lack of diversity and range is troubling, and I'm ∝
PREG_SPLIT_NO_EMPTY);
?>
<?php
// check spelling
PREG_SPLIT_NO_EMPTY);
if (!pspell_check($dict, $w)) {
$errors[] = $w;
}
// if errors exist
if (sizeof($errors) > 0) {
?>
<?php
$str = trim($str);
$wordStats[strtolower($w)]++;
// result: "baa"
?>
Searching Strings
<?php
?>
<?php
// define string
// result: "Match"
?>
?>