Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ifrah Shahid
lab-exercises
Commits
9d51141c
Commit
9d51141c
authored
Sep 16, 2016
by
Sorrel Harriet
Browse files
removing swp file
parent
4363a905
Changes
1
Hide whitespace changes
Inline
Side-by-side
week-1/test_app/includes/functions.php~
deleted
100644 → 0
View file @
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> </td>'
;
}
if
(
isset
(
$isbn
))
{
$book_string
.
=
'<td>'
.
htmlentities
(
$isbn
)
.
'</td>'
;
}
else
{
$book_string
.
=
'<td> </td>'
;
}
if
(
isset
(
$price
))
{
$book_string
.
=
"<td>£"
.
htmlentities
(
$price
)
.
"</td>"
;
}
else
{
$book_string
.
=
'<td> </td>'
;
}
if
(
isset
(
$date
))
{
$date_string
=
formatDate
(
$date
);
$book_string
.
=
"<td>"
.
htmlentities
(
$date_string
)
.
"</td>"
;
}
else
{
$book_string
.
=
'<td> </td>'
;
}
if
(
isset
(
$authors
))
{
$author_string
=
formatAuthors
(
$authors
);
$book_string
.
=
"<td>"
.
$author_string
.
"</td>"
;
}
else
{
$book_string
.
=
'<td> </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
;
}
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment