Bon bref, j'ai trouvé un bout de code sur la toile que j'ai bidouillé pour afficher les derniers messages du forum.
Le script fonctionne, mais est il propre ?
- Je ne suis pas arrivé à inclure la fonction format_url
Est-ce que le formatage des urls est correct ? (mod rewrite avancé)
Merci pour votre oeil expert
- Code: Tout sélectionner
<?php
include ("config.php");
$link = mysql_connect ($dbhost,$dbuser,$dbpasswd) or die ('Erreur : '.mysql_error() );
mysql_select_db($dbname) or die ('Erreur :'.mysql_error());
$select = "SELECT topic_title,topic_id,topic_poster,forum_id,topic_last_poster_name,topic_last_post_time FROM forum_topics where forum_id !='37' ORDER BY topic_last_post_time DESC limit 8";
$result = mysql_query($select,$link) or die ('Erreur : '.mysql_error() );
while($row = mysql_fetch_array($result))
{
$topic_id = $row['topic_id'];
$titre = $row['topic_title'];
$posteur = $row['topic_last_poster_name'];
########## Début format URL ##########
$annonce= $titre;
$annonce = preg_replace("`\[.*\]`U","",$annonce);
$annonce = preg_replace('`&(amp;)?#?[a-z0-9]+;`i','-',$annonce);
$annonce = htmlentities($annonce, ENT_COMPAT, 'UTF-8');
$annonce = preg_replace( "`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i","\\1", $annonce );
$annonce = preg_replace( array("`[^a-z0-9]`i","`[-]+`") , "-", $annonce);
$annonce = ( $annonce == "" ) ? $type : strtolower(trim($annonce, '-'));
########## Fin format URL ##########
$titre_lien= (strlen($titre) > 32) ? substr($titre, 0,29).'...' : $titre;
echo '<a href="/forum/'.$annonce.'-t'.$topic_id.'.html">'.ucfirst(strtolower($titre_lien)).'</a> - '.$posteur.'<br>';
}
mysql_free_result($result);
mysql_close();
?>

Français |
Anglais


