halohalo
bnmbnmbnhjkhjkhjkhjktyutyutyuytutyutyutyhgjgjghjgjghjguytutyry
/
home
/
aramiyarkai
/
public_html
/
Upload FileeE
HOME
<?php function seo_url($table,$seo_url_field,$title_field){ global $link; # this script set unique friendly url for articles //echo "SELECT * FROM $table WHERE $seo_url_field = ''"; # where we get all articles with empty friendly url $query = mysqli_query($link, "SELECT * FROM $table WHERE $seo_url_field = '' "); # for each article with empty seo_url while($row = mysqli_fetch_assoc($query)){ # get friendly url from title //echo "test"; $new_seo_url = $vl_url_string = friendly_seo_string($row[$title_field]); //echo $row[$title_field]; //exit; $counter = 1; $intial_seo_url = $new_seo_url; //echo $new_seo_url; # while we not found unique friendly url while(mysqli_num_rows(mysqli_query($link, "SELECT * FROM $table WHERE $seo_url_field = '$new_seo_url' "))){ # if friendly url is already used by other article # -> increase counter until we find free url $counter++; # we reapeat this until url-2 url-3 url-4..... until we find not used url for articles $new_seo_url = "{$intial_seo_url}-{$counter}"; } # END while # once we found friendly url we set it to articles table, # then we can use it to build our frinedly url //echo $new_seo_url; mysqli_query($link, "UPDATE $table SET $seo_url_field = '{$new_seo_url}' WHERE id = '{$row['id']}' "); } # END while } /** * function, receives string, returns seo friendly version for that strings, * sample: 'Hotels in Buenos Aires' => 'hotels-in-buenos-aires' * - converts all alpha chars to lowercase * - converts any char that is not digit, letter or - into - symbols into "-" * - not allow two "-" chars continued, converte them into only one syngle "-" */ 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; } # friendly_seo_string() ?>