<?php
$stmt = $pdo->prepare(
"SELECT id, title, price FROM listings
WHERE id = :id LIMIT 1"
);
$stmt->execute(['id' => (int) $_GET['id']]);
$listing = $stmt->fetch(PDO::FETCH_ASSOC);
if ($listing) {
echo htmlspecialchars(
$listing['title'],
ENT_QUOTES,
'UTF-8'
);
}
<?php
function e(?string $value): string
{
return htmlspecialchars(
$value ?? '',
ENT_QUOTES | ENT_SUBSTITUTE,
'UTF-8'
);
}
?>
<h2><?= e($listing['title'] ?? '') ?></h2>
<?php
function slugify(string $text): string
{
$text = mb_strtolower(trim($text), 'UTF-8');
$text = strtr($text, [
'ə' => 'e', 'ı' => 'i',
'ö' => 'o', 'ü' => 'u',
'ğ' => 'g', 'ş' => 's',
'ç' => 'c',
]);
$text = preg_replace('/[^a-z0-9]+/', '-', $text) ?? '';
return trim($text, '-');
}
echo slugify('BMW X5 E53 2005');
// bmw-x5-e53-2005
<?php
function money(float|int $amount): string
{
return number_format($amount, 0, ',', ' ') . ' AZN';
}
echo money(25200);
// 25 200 AZN