<?php
include_once ('../../db.php');
$bdd = new DB();
$rows = $bdd->getAll("SELECT project_id,project_name FROM project WHERE url_name=''");
foreach($rows as $row)
{
	$new_friendly_url=$vl_url_string=friendly_seo_string($row['project_name']);
	$counter=1;
    $intial_friendly_url=$new_friendly_url;
	
	while($rows1=$bdd->getAll("SELECT url_name FROM project WHERE url_name = '$new_friendly_url'"))
	{
		foreach($rows1 as $row1)	
		{
			$counter++;  
			$new_friendly_url = "{$intial_friendly_url}-{$counter}";
			
		}
	}
	$query = $bdd->execute("UPDATE project SET url_name = '{$new_friendly_url}' WHERE project_id = '{$row['project_id']}'");
}

function friendly_seo_string($vp_string)
{
    $vp_string = trim($vp_string);   
    $vp_string = html_entity_decode($vp_string);
    $vp_string = strip_tags($vp_string);
    $vp_string = strtolower($vp_string);
    $vp_string = preg_replace('~[^ a-z0-9_.]~', ' ', $vp_string);
    $vp_string = preg_replace('~ ~', '-', $vp_string);
    $vp_string = preg_replace('~-+~', '-', $vp_string);
    return $vp_string;
}
?> 