Ernest's Pirate Translator 🏴☠️
Enter a phrase below and see how it sounds on the high seas!
Enter a phrase below and see how it sounds on the high seas!
<?php
include('../includes/header.php');
error_reporting(E_ALL);
echo "<h1>Ernest's Pirate Translator 🏴☠️</h1>";
echo "<p>Enter a phrase below and see how it sounds on the high seas!</p>";
?>
<style>
/* Fade-in animation */
.fade-in {
opacity: 0;
transform: translateY(10px);
animation: fadeInUp 0.8s ease forwards;
}
@keyframes fadeInUp {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
/* Form styling */
form {
background-color: #f8fafc;
padding: 15px;
border-radius: 8px;
max-width: 500px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
input[type="text"] {
padding: 8px;
width: 90%;
margin: 5px 0;
}
input[type="submit"] {
background-color: #1e3a8a;
color: white;
border: none;
padding: 8px 16px;
border-radius: 6px;
cursor: pointer;
transition: background 0.3s;
}
input[type="submit"]:hover {
background-color: #2563eb;
}
</style>
<div class="fade-in">
<form method="post" action="">
<label for="phrase"><strong>Enter your text:</strong></label><br>
<input type="text" id="phrase" name="phrase" size="60" required>
<input type="submit" value="Translate to Pirate!">
</form>
</div>
<hr>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$text = trim($_POST['phrase']);
$lower = strtolower($text);
// Pirate dictionary
$dictionary = [
"hello" => "ahoy",
"hi" => "ahoy",
"my" => "me",
"friend" => "matey",
"is" => "be",
"are" => "be",
"you" => "ye",
"your" => "yer",
"the" => "th’",
"and" => "n’",
"yes" => "aye",
"no" => "nay",
"stop" => "avast",
"money" => "booty",
"drink" => "grog"
];
// Replace words
$pirate = str_replace(array_keys($dictionary), array_values($dictionary), $lower);
$pirate = ucfirst($pirate);
echo "<div class='fade-in'>";
echo "<h2>⚓ Translation Results ⚓</h2>";
echo "<p><strong>Original phrase:</strong> $text</p>";
echo "<p><strong>Pirate translation:</strong> $pirate ☠️</p>";
// String info
$words = str_word_count($text);
echo "<p><strong>Word count:</strong> $words</p>";
echo "<p><strong>Uppercase version:</strong> " . strtoupper($pirate) . "</p>";
echo "<p><strong>Reversed text:</strong> " . strrev($pirate) . "</p>";
// Pirate rating
$replacedCount = 0;
foreach ($dictionary as $english => $pirateWord) {
if (stripos($lower, $english) !== false) {
$replacedCount++;
}
}
$totalWords = count($dictionary);
$piratePercent = round(($replacedCount / $totalWords) * 100);
if ($piratePercent < 20) {
$ratingMsg = "Ye barely sound like a cabin boy!";
} elseif ($piratePercent < 50) {
$ratingMsg = "Arrr... ye be gettin’ the hang of it!";
} elseif ($piratePercent < 80) {
$ratingMsg = "Now that’s some proper pirate tongue!";
} else {
$ratingMsg = "Shiver me timbers! Ye be a true sea dog!";
}
// Pirate Meter
echo "<hr>";
echo "<h3>🏴☠️ Pirate Rating: $piratePercent%</h3>";
echo "<div style='background:#1e293b; border-radius:10px; width:100%; max-width:400px; height:30px; overflow:hidden; position:relative; margin-bottom:10px;'>
<div id='meter' style='height:100%; width:0; background:red; display:flex; align-items:center; justify-content:center; font-weight:bold; color:#0b1220; text-shadow:0 0 3px rgba(255,255,255,0.8);'></div>
</div>";
echo "<p><em>$ratingMsg</em></p>";
// JS animation
echo "<script>
const bar = document.getElementById('meter');
let width = 0;
const target = $piratePercent;
const getColor = (percent) => {
const r = percent < 50 ? 255 : Math.floor(255 - (percent - 50) * 5.1);
const g = percent < 50 ? Math.floor(percent * 5.1) : 255;
return `rgb(${r},${g},0)`;
};
const fill = setInterval(() => {
if (width >= target) clearInterval(fill);
else {
width++;
bar.style.width = width + '%';
bar.style.backgroundColor = getColor(width);
bar.textContent = width + '%';
}
}, 15);
</script>";
echo "</div>";
}
?>
<?php include('../includes/footer.php'); ?>