kkkkkk
Category: Technology | Author: Anonymous | Published: January 20, 2025
// Funzioni helper per il generatore di slug
function generateUniqueSlug($conn, $title, $category_id) {
$slug = generateSlug($title);
$originalSlug = $slug;
$counter = 1;
while (true) {
$checkSlugQuery = "SELECT COUNT(*) as count FROM articles WHERE slug = '$slug' AND category_id = $category_id";
$result = $conn->query($checkSlugQuery);
if ($result && $result->fetch_assoc()['count'] == 0) {
break;
}
$slug = $originalSlug . '-' . $counter;
$counter++;
}
return $slug;
}
function generateSlug($string) {
$slug = strtolower($string);
$slug = preg_replace('/[^a-z0-9]+/i', '-', $slug);
$slug = trim($slug, '-');
return $slug;
}
?>