Thursday, June 23, 2011

Thursday 6/23/2011


<?php
class ShopProduct {
public $title;
public $producerMainName;
public $producerFirstName;
public $price;

function __construct($title, $firstName, $mainName, $price){
$this->title = $title;
$this->producerFirstName = $firstName;
$this->producerMainName = $mainName;
$this->price = $price;
}

function getProducer(){
return "{$this->producerFirstName} . {$this->producerMainName}";
}
function getTitle(){
return $this->title;
}
function getSummaryLine(){
$base = "{$this->title} ({$this->producerMainName}, ";
$base .= "{$this->producerFirstName})";
return $base;
}

} //end class ShopProduct


abstract class ShopProductWriter{
protected $products = array();

public function addProduct(ShopProduct $shopProduct){
$this->products[]=$shopProduct;
}

abstract public function write();
}

class XmlProductWriter extends ShopProductWriter{
public function write(){
$str = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$str .= "<products>\n";
foreach($this->products as $shopProduct){
$str .= "\tgetTitle()}\">\n";
$str .= "\t\t<summary>\n";
$str .="\t\t{$shopProduct->getSummaryLine()}\n";
$str .="\t\t</summary>\n";
$str .= "\t\t</product>\n";
}
$str .= "</products>\n";
print $str;
}
}

class TextProductWriter extends ShopProductWriter{
public function write(){
$str = "PRODUCTS:\n";
foreach($this->products as $shopProduct){
$str .= $shopProduct->getSummaryLine()."\n";
}
print $str;
}
}

$dw = new shopProduct("PHP for Fun", "John", "Martin", 18.99);
$xml = new XmlProductWriter();
$xml->addProduct($dw);
$xml->write();

?>

here is a tutorial on time and getting the last modification


<?php
echo "This file was last updated on ";
echo date('l d F Y, \a\t H:i:s T', getlastmod());
echo ". ";
?>




<?php
$file = "time2.php";
echo "The file $file was last updated on ";
echo date('l d F Y, \a\t H:i:s T', filemtime("./$file"));
echo ". ";

?>


And here is the final tutorial for the day on time


<?php
$file = 'time3.php';
$data = stat($file);
$accessed = $data['atime'];
$modified = $data['mtime'];
$created = $data['ctime'];

echo "The file $file was...
\n";
echo "last accessed" . date('l d f Y, \a\t H:i:d', $accessed) . ",
\n";
echo "last modified " . date('l d F Y, \a\t H:i:s', $modified) . ",
\n";
echo "and created" . date('l d F Y, \a\t H:i:s', $created) . ". ";
?>

No comments: