<?php
/**
     * Generate Slugs from name
     */
    function generateSlug($name, $table)
    {       
        // transliterate
     //   $text = iconv('utf-8', 'ISO-8859-1//TRANSLIT', $text);
        include('config/dbcon.php');

        // Convert all dashes, spaces, & undescores to hyphens
        $name = str_replace(' - ', '-', $name);
        $name = str_replace('—', '-', $name);
        $name = str_replace('‒', '-', $name);
        $name = str_replace('―', '-', $name);
        $name = str_replace('_', '-', $name);
        $name = str_replace(' ', '-', $name);

        // Remove everything except 0-9, a-z, A-Z and hyphens
        $name = preg_replace('/[^A-Za-z0-9-]+/', '', $name);
        
        // Make lowercase - no need for this to be multibyte
        // since there are only 0-9, a-z, A-Z and hyphens left in the string

        $slug = strtolower($name);

        $query = "Select slug from $table WHERE slug = '$slug'";
        

        $query_run = mysqli_query($con, $query);

       // if(!$con){return "VUA";}
        if(mysqli_num_rows($query_run) > 0)
        {


            $rnd = rand(10,1000); 
            $slug .= "_".$rnd;
            //$slug.'_$rnd';
        }

        return $slug;
    }


?>