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 39 40 41 42 43
|
<?php
ob_start();
mysql_connect("localhost","root","");
mysql_select_db("cour");
$contents = ob_get_contents();
ob_end_clean();
if(preg_match_all(
'#<a href="donne.php\?scat=([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 nomsoucategorie
FROM souscategorie
WHERE idsoucategorie = '.$article_id;
$result = mysql_query($sql)
or die(__LINE__.' : '.mysql_error());
if($article = mysql_fetch_assoc($result)){
$new_url =
'<a href="donne-'.$article_id.'.html" '
.$article['nomsoucategorie'] .'</a>'
;
$contents = str_replace($pattern, $new_url, $contents);
};
};
};
// Afficher la page
echo $contents;
?> |
Partager