1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| function replace_mod_rewriting($contents)
{
$http = 'http://www2.moviefactory.fr/';
// Récupérer les liens videos à l'aide d'une expression régulière
if(preg_match_all(
'#<a href="fiche-video.php\?id=([0-9]+)">(.+)</a>#Usi',
$contents,
$matches,
PREG_SET_ORDER))
{
// Parcourir les liens et les réécrire à l'aide de la base de données
foreach($matches as $match){
$pattern = $match[0];
$article_id = $match[1];
$anchor = $match[2];
$sql = 'SELECT `id`,`nom` FROM `videos` WHERE `id` = '.$article_id;
$result = sql_query($sql,'AFFICHE TITRE VIDEO POUR REWRITING');
if($article = mysql_fetch_assoc($result)){
$new_url =
'<a href="'.$http.'videos/'.rewriting($article['nom']).'-'.$article['id'].'.html" '
.'title="'.$article['nom'].'">'
.$anchor
.'</a>';
$contents = str_replace($pattern, $new_url, $contents);
}
}
}
// Afficher la page
echo $contents;
} |
Partager