Commit 9d51141c authored by Sorrel Harriet's avatar Sorrel Harriet
Browse files

removing swp file

parent 4363a905
<?php
function formatMoney($number) {
$formatted = number_format($number, 2);
return $formatted;
}
function formatAuthors($author_array) {
if ( count($author_array) == 1 ) {
return $author_array[0];
} elseif ( count($author_array) == 2 ) {
return $author_array[0] . " and " . $author_array[1];
} else {
$author_string = "";
for ($i=0;$i<count($author_array);$i++) {
if ($i==count($author_array)-2) {
$author_string .= " and ";
} elseif ( $i==count($author_array)-1) {
$author_string .= $author_array[$i];
} else {
$author_string .= $author_array[$i].", ";
}
}
return $author_string;
}
}
// Function to return formatted string of book fields
function formatBook( $title, $isbn, $price, $date, $authors ) {
$book_string ='<tr>';
if (isset($title)) {
$book_string .= '<td>'.htmlentities($title).'</td>';
} else {
$book_string .= '<td>&nbsp;</td>';
}
if (isset($isbn)) {
$book_string .= '<td>'.htmlentities($isbn).'</td>';
} else {
$book_string .= '<td>&nbsp;</td>';
}
if (isset($price)) {
$book_string .= "<td>&pound;".htmlentities($price)."</td>";
} else {
$book_string .= '<td>&nbsp;</td>';
}
if (isset($date)) {
$date_string = formatDate($date);
$book_string .= "<td>".htmlentities($date_string)."</td>";
} else {
$book_string .= '<td>&nbsp;</td>';
}
if (isset($authors)) {
$author_string = formatAuthors( $authors );
$book_string .= "<td>".$author_string."</td>";
} else {
$book_string .= '<td>&nbsp;</td>';
}
$book_string .='</tr>';
return $book_string;
}
// Function to standardise date formats
function formatDate($date) {
$timestamp = strtotime($date);
$date_string = date('dS F Y', $timestamp);
return $date_string;
}
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment