• Copyright© 2025 xPralak Designs - Joseph Downey
<div id="page">
<?php include('includes/header.php'); ?>
<h1 class='page-heading'>Joe's | Example: Strings Mastery</h1>
<div class="examplenavbar">
<button onclick="showSection('encrypt')">Encryption</button>
<button onclick="showSection('madlibs')">Mad Libs</button>
<button onclick="showSection('secret')">Secret Code</button>
<button onclick="showSection('username')">Username Generator</button>
<button onclick="showSection('password')">Password Checker</button>
</div>
<div class="content-area">
<div id="encrypt" class="content <?php echo isset($_POST['encrypt_btn']) ? 'active' : ''; ?>">
<form method="POST">
<h2>String Encryption</h2>
<input type="text" name="encrypt_text" placeholder="Enter text" required>
<button type="submit" name="encrypt_btn">Encrypt</button>
</form>
<?php
if (isset($_POST['encrypt_btn'])) {
$text = $_POST['encrypt_text'];
$textLength = strlen($text); // Count number of characters
echo '<div class="content-right">';
echo '<pre>';
echo "<p>Original Text: $text</p>";
echo "<p>Text Length: $textLength characters</p>";
echo "<p>Base64: " . base64_encode($text) . "</p>";
echo "<p>ROT13: " . str_rot13($text) . "</p>";
echo "<p>MD5 Hash: " . md5($text) . "</p>";
echo "</pre>";
echo '</div>';
}
?>
</div>
<div id="madlibs" class="content <?php echo isset($_POST['madlibs_btn']) ? 'active' : ''; ?>">
<form method="POST" id="madlibsForm">
<h2>Mad Libs</h2>
<input type="text" name="adjective" placeholder="Adjective (optional)" >
<input type="text" name="noun" placeholder="Noun (optional)" >
<input type="text" name="verb" placeholder="Verb (optional)" >
<button type="submit" name="madlibs_btn">Generate</button>
</form>
<?php
// Predefined lists of words
$adjectives = ['funny', 'fast', 'loud', 'crazy', 'smelly', 'green'];
$nouns = ['dog', 'car', 'mountain', 'chair', 'apple', 'planet'];
$verbs = ['run', 'jump', 'sing', 'dance', 'sleep', 'kick'];
// Predefined sentence templates
$templates = [
"Today I saw a %s %s %s on the street!",
"It was a %s %s that decided to %s on the sidewalk.",
"A %s %s was caught %sing near the park!",
"I watched a %s %s %s across the field.",
"The %s %s started to %s while I walked by!"
];
if (isset($_POST['madlibs_btn'])) {
// Get user input or pick a random word from the list
$adj = !empty($_POST['adjective']) ? $_POST['adjective'] : $adjectives[array_rand($adjectives)];
$noun = !empty($_POST['noun']) ? $_POST['noun'] : $nouns[array_rand($nouns)];
$verb = !empty($_POST['verb']) ? $_POST['verb'] : $verbs[array_rand($verbs)];
// Select a random sentence template
$sentence = $templates[array_rand($templates)];
// Calculate the total length of the inputs
$totalLength = strlen($adj) + strlen($noun) + strlen($verb);
echo '<div class="content-right">';
echo '<pre>';
echo "<p>Original Inputs:</p>";
echo "<p>Adjective: $adj</p>";
echo "<p>Noun: $noun</p>";
echo "<p>Verb: $verb</p>";
echo "<p>Total Input Length: $totalLength characters</p>";
echo "</pre>";
// Display the randomized Mad Lib story
echo '<pre>';
echo "<p>" . sprintf($sentence, $adj, $noun, $verb) . "</p>";
echo "</pre>";
echo '</div>';
}
?>
</div>
<div id="secret" class="content <?php echo isset($_POST['secret_btn']) ? 'active' : ''; ?>">
<form method="POST">
<h2>Secret Code</h2>
<input type="text" name="secret_text" placeholder="Enter text" required>
<button type="submit" name="secret_btn">Scramble</button>
</form>
<?php
if (isset($_POST['secret_btn'])) {
$text = $_POST['secret_text'];
$textLength = strlen($text); // Count number of characters
echo '<div class="content-right">';
echo "<pre>";
echo "<p>Original Text: $text</p>";
echo "<p>Text Length: $textLength characters</p>";
echo "<p>Scrambled: " . str_shuffle($text) . "</p>";
echo "</pre>";
echo '</div>';
}
?>
</div>
<div id="username" class="content <?php echo isset($_POST['username_btn']) ? 'active' : ''; ?>">
<form method="POST">
<h2>Username Generator</h2>
<input type="text" name="username" placeholder="Enter name" required>
<button type="submit" name="username_btn">Generate</button>
</form>
<?php
if (isset($_POST['username_btn'])) {
$name = $_POST['username'];
$nameLength = strlen($name); // Count number of characters
echo '<div class="content-right">';
echo "<pre>";
echo "<p>Original Name: $name</p>";
echo "<p>Text Length: $nameLength characters</p>";
echo "<p>Generated Username: " . ucfirst(strtolower($name)) . "_" . rand(100, 999) . "</p>";
echo "</pre>";
echo '</div>';
}
?>
</div>
<div id="password" class="content <?php echo isset($_POST['password_btn']) ? 'active' : ''; ?>">
<form method="POST">
<h2>Password Strength Checker</h2>
<input type="text" name="password" placeholder="Enter password" required>
<button type="submit" name="password_btn">Check</button>
</form>
<?php
if (isset($_POST['password_btn'])) {
$password = $_POST['password'];
$passwordLength = strlen($password); // Count number of characters
echo '<div class="content-right">';
echo "<pre>";
echo "<p>Original Password: $password</p>";
echo "<p>Text Length: $passwordLength characters</p>";
echo "</pre>";
$score = 0;
if (strlen($password) >= 8) $score++;
if (preg_match('/[A-Z]/', $password)) $score++;
if (preg_match('/[0-9]/', $password)) $score++;
if (preg_match('/[!@#$%^&*()]/', $password)) $score++;
echo "<pre>";
echo "<p>Password Strength: ";
echo ($score == 4) ? "Strong" : (($score == 3) ? "Medium" : "Weak");
echo "</p>";
echo "</pre>";
echo '</div>';
}
?>
</div>
</div>
<?php include('includes/footer.php'); ?>
</div>
<script>
function showSection(sectionId) {
document.querySelectorAll('.content').forEach(div => div.classList.remove('active'));
document.getElementById(sectionId).classList.add('active');
}
</script>