PSA4 Technical - Predefined Functions
PSA4 Technical - Predefined Functions
PRE-SUMMATIVE ASSESSMENT
4
PHP PRE DEFINED FUNCTIONS
1. Create 5 different short story webpages and convert your stories into a
web-based form, use include() and require() functions to connect all pages
integrate with HTML and CSS (Put images on the stories). See the format
below:
1.1. SCREENSHOTS
header.php
<header class="main-header">
<div class="header-content">
<div class="logo">
<a href="index.php">
<img src="images/logo.webp" alt="Genshin Impact" class="logo-img">
</a>
<link href="https://fonts.googleapis.com/css2?
family=Abhaya+Libre:ital,wght@0,800&display=swap" rel="stylesheet">
</div>
<nav class="main-nav">
<a href="skirk_story.php" class="nav-link">Skirk</a>
<a href="dahlia_story.php" class="nav-link">Dahlia</a>
<a href="shenhe_story.php" class="nav-link">Shenhe</a>
<a href="mavuika_story.php" class="nav-link">Mavuika</a>
<a href="emilie_story.php" class="nav-link">Emilie</a>
</nav>
<a href="https://genshin.hoyoverse.com/en/" class="reference-pill"
target="_blank">Reference</a>
</div>
</header>
footer.php
<footer class="main-footer">
<div class="footer-content">
<p><i>All assets are used for educational purposes only. All Rights reserved to
COGNOSPHERE.</i></p>
</div>
</footer>
<main class="main-content">
<div class="hero-section">
<div class="character-showcase">
<img src="images/index.png" alt="Background" class="bg-image">
<div class="character-info">
<div class="stars">
</div>
<h1>Tales of Teyvat</h1>
<p class="description">
In the vast world of Teyvat, countless stories unfold. From the icy
peaks of Dragonspine
to the depths of the Abyss, each character carries their own tale
of triumph, loss, and destiny.
Discover the untold stories that shape their journeys.
</p>
<div class="character-nav">
<?php include 'includes/character_icons.php'; ?>
</div>
</div>
</div>
</div>
</main>
story1.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Skirk's Tale</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<?php require 'includes/header.php'; ?>
<div class="story-layout">
<!-- Background Image -->
<div class="story-background">
<img src="images/skirk_bg.webp" class="bg-image-story">
</div>
<p>She exhaled, calm. "Still not strong enough," she whispered to the dark.
Her eyes narrowed. Tartaglia had left this place.</p>
For convenience, the rest of the source code of the stories two through five will not be
included as it is repetitive.
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #1a1428 0%, #2d1b42 50%, #4a2c5a 100%);
color: white;
min-height: 100vh;
position: relative;
overflow-x: hidden;
}
/* Background Effects */
body::before {
content: '';
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background:
radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.15) 0%, transparent 50%),
radial-gradient(circle at 40% 40%, rgba(139, 92, 246, 0.2) 0%, transparent 50%);
pointer-events: none;
z-index: -1;
}
.reference-pill {
display: inline-block;
background: rgba(255,255,255,0.7);
color: #222;
border-radius: 999px;
padding: 10px 32px;
font-weight: bold;
font-size: 1.1rem;
margin-left: 32px;
transition: background 0.2s, box-shadow 0.2s;
cursor: pointer;
border: none;
text-decoration: none;
}
.reference-pill:hover {
background: #fff;
box-shadow: 0 0 10px #aeeaff;
cursor: pointer;
}
/* Header Styles */
.main-header {
background: rgba(26, 20, 40, 0.9);
backdrop-filter: blur(10px);
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
padding: 1rem 0;
.header-content {
max-width: 1200px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 2rem;
}
.logo-img {
height: 47px;
width: 76px;
}
.main-nav {
display: flex;
gap: 2rem;
}
.nav-link {
color: rgba(255, 255, 255, 0.8);
text-decoration: none;
font-weight: 500;
padding: 0.5rem 1rem;
border: 1px solid transparent;
border-radius: 20px;
transition: all 0.3s ease;
position: relative;
}
.nav-link:hover, .nav-link.active {
color: #ffffff;
border-color: rgba(139, 92, 246, 0.5);
background: rgba(139, 92, 246, 0.2);
box-shadow: 0 0 15px rgba(139, 92, 246, 0.3);
}
/* Main Content */
.main-content {
margin-top: 80px;
min-height: calc(100vh - 80px);
}
.hero-section {
position: relative;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.character-showcase {
position: relative;
width: 100%;
.bg-image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
z-index: -1;
}
.character-info {
text-align: center;
max-width: 600px;
padding: 2rem;
background: rgba(26, 20, 40, 0.8);
backdrop-filter: blur(15px);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 20px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}
.stars {
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
margin-bottom: 1rem;
}
.stars img {
width: 100px;
height: auto;
}
.character-title-flex {
display: flex;
align-items: center;
gap: 20px;
}
.character-logo {
width: 52px;
height: 58.5px;
object-fit: contain;
}
.character-title, .character-name {
font-size: 1.2rem;
font-weight: bold;
color: #ffd700;
text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}
.character-info h1 {
font-size: 3rem;
.description {
font-size: 1.1rem;
line-height: 1.6;
margin-bottom: 2rem;
color: rgba(255, 255, 255, 0.9);
}
/* Character Icons */
.character-nav {
margin-top: 2rem;
}
.character-icons {
display: flex;
justify-content: center;
gap: 1rem;
}
.character-icon {
display: block;
transition: transform 0.3s ease;
}
.character-icon:hover {
transform: scale(1.1);
}
.character-icon .icon {
border-radius: 50%;
border: 2px solid transparent;
transition: all 0.3s ease;
}
.character-icon .icon:hover {
border-color: rgba(139, 92, 246, 0.8);
box-shadow: 0 0 15px rgba(139, 92, 246, 0.4);
}
.story-background {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
.bg-image-story {
width: 1920px;
height: 1015px;
object-fit: cover;
object-position: center;
min-width: 100%;
min-height: 100%;
}
.story-left-content {
width: 50%;
height: 100%;
padding: 100px 80px 60px 200px;
display: flex;
flex-direction: column;
justify-content: flex-start;
z-index: 10;
margin-top: 20px;
}
.story-right-content {
position: absolute;
right: 0;
bottom: 0;
top: 0;
width: auto;
height: 100%;
display: flex;
align-items: flex-end;
justify-content: flex-end;
pointer-events: none;
z-index: 2;
background: transparent;
}
/* Logo */
.story-logo {
margin-bottom: 40px;
}
.logo-story {
height: 50px;
width: auto;
}
.character-label {
font-size: 18px;
color: #ffffff;
font-weight: normal;
margin-bottom: 10px;
display: flex;
align-items: center;
gap: 10px;
.star-rating {
margin-bottom: 15px;
}
.star-image {
height: 30px;
width: auto;
}
.character-name-large {
font-family: 'Abhaya Libre', serif;
font-size: 4rem;
font-weight: bold;
color: #ffffff;
margin: 0;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
.rarity-image {
height: 40px;
width: auto;
}
/* Story Content */
.story-content-text {
max-width: 500px;
margin-bottom: 60px;
flex: 1;
}
.story-content-text p {
font-size: 16px;
line-height: 1.6;
color: #ffffff;
margin-bottom: 20px;
text-align: left;
}
.character-icons-bottom img {
width: 90px;
height: 90px;
object-fit: contain;
border-radius: 50%;
transition: transform 0.2s, box-shadow 0.2s;
background: transparent;
box-sizing: border-box;
}
.icon-link {
.character-icon-img {
border-radius: 50%;
transition: all 0.3s ease;
cursor: pointer;
}
/* Character Image */
.character-image-container {
width: auto;
height: 100%;
display: flex;
align-items: flex-end;
justify-content: flex-end;
overflow: visible;
background: transparent;
}
.character-main-image {
height: 95vh; /* or 100% if you want it to fill the height */
width: auto;
max-width: none;
object-fit: contain;
object-position: right bottom;
border: none;
background: transparent;
display: block;
pointer-events: none;
}
.navigation-buttons {
margin-top: 3rem;
padding-top: 2rem;
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.story-navigation {
display: flex;
justify-content: center;
gap: 1rem;
flex-wrap: wrap;
}
.nav-btn {
padding: 0.8rem 1.5rem;
background: rgba(139, 92, 246, 0.2);
border: 1px solid rgba(139, 92, 246, 0.5);
border-radius: 25px;
color: white;
text-decoration: none;
font-weight: 500;
transition: all 0.3s ease;
}
.nav-btn:hover {
background: rgba(139, 92, 246, 0.4);
box-shadow: 0 0 15px rgba(139, 92, 246, 0.3);
transform: translateY(-2px);
.home-btn {
background: rgba(255, 215, 0, 0.2);
border-color: rgba(255, 215, 0, 0.5);
}
.home-btn:hover {
background: rgba(255, 215, 0, 0.4);
box-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
}
/* Footer */
.main-footer {
background: rgba(26, 20, 40, 0.9);
backdrop-filter: blur(10px);
padding: 2rem 0;
text-align: center;
margin-top: 4rem;
}
.footer-content p {
color: rgba(255, 255, 255, 0.6);
font-size: 0.9rem;
}
.main-nav {
gap: 1rem;
}
.nav-link {
padding: 0.4rem 0.8rem;
font-size: 0.9rem;
}
.character-info h1 {
font-size: 2rem;
}
.story-overlay {
flex-direction: column;
text-align: center;
gap: 1.5rem;
}
.character-portrait img {
width: 150px;
height: 200px;
}
.story-info h1 {
font-size: 2rem;
}
.character-icon .icon {
width: 50px;
height: 50px;
}
.story-navigation {
gap: 0.5rem;
}
.nav-btn {
padding: 0.6rem 1rem;
font-size: 0.
}
}
2.1. SCREENSHOT
function replace_vowels($str) {
return preg_replace('/[aeiou]/i', '@', $str);
}
?>
<?php
echo '<table>
<tr>
<th>Name</th>
<th>Number of characters</th>
<th>Uppercase first character</th>
<th>Replace vowels with @</th>
<th>Check position of character "a"</th>
<th>Reverse name</th>
</tr>';
echo "<tr>
<td>$name</td>
<td>$num_chars</td>
<td>$ucfirst</td>
<td>$vowel_replaced</td>
<td>$pos_a_display</td>
<td>$reverse</td>
</tr>";
}
echo '</table>';
?>
</body>
</html>
styles.css
h1 {
text-align: center;
color: #fff;
font-family: 'Segoe UI', Arial, sans-serif;
font-size: 2.5em;
}
table {
border-collapse: collapse;
width: 90%;
margin: 40px auto;
background: #232946;
color: #fff;
font-family: 'Segoe UI', Arial, sans-serif;
box-shadow: 0 4px 24px rgba(0,0,0,0.12);
border-radius: 12px;
overflow: hidden;
}
caption {
font-size: 1.6em;
font-weight: bold;
margin-bottom: 16px;
color: #eebd35;
letter-spacing: 1px;
padding: 16px 0 0 0;
}
th, td {
padding: 14px 18px;
border-bottom: 1px solid #393e5c;
text-align: center;
}
th {
background: #393e5c;
color: #eebd35;
font-size: 1.1em;
}
tr:last-child td {
border-bottom: none;
}
tr:nth-child(even) td {
background: #2d325a;
}
td {
font-size: 1em;
}
In PHP, both include and require are used to insert the contents of one PHP file into another. The key difference lies
in how they handle errors. When a file is not found, include will emit a warning but the script will continue to execute,
which makes it useful when the file is not essential. On the other hand, require will produce a fatal error and stop the
execution of the script entirely, making it better suited for files that are critical to the application, such as configuration
files or core logic. Choosing between the two depends on how important the external file is to the flow of your
program.
VIII. REFERENCES
1. https://www.w3schools.com/css/
2. https://www.w3schools.com/html/
3. https://www.w3schools.com/php/php_variables.asp
4. https://www.w3schools.com/php/php_constants.asp
5. https://www.w3schools.com/php/php_includes.asp
6. https://www.w3schools.com/php/php_string.asp