Script News...lire la suite
le 17/07/2008 à 18:01
hello. je maitrise le script news mais j'aimerais avoir un lien "lire la suite" qui gènere automatiquement une page avec la news entiere...
merci pour l'aide :-)
le 17/07/2008 à 18:06
Keika
Déconnecté
Le PHP --> C'est dur !
salut,
toute news a un id unique. Tu fais un lien qui integre cet id. Apres recuperation de l'id contenu dans l'url, tu va chercher ta news et tu l'affiches.
Facile.
Bye
le 17/07/2008 à 22:48
i M@N
Déconnecté
One Love, One Heart, One Unity.
Hello.
Voilà la fonction cut_string qui va couper le texte de ta news au nombre de caractères que tu veux :
<?php
function cut_string ( $string , $charlimit ) { if ( strlen ( $string ) > $charlimit ) { $string = substr ( $string , '0' , $charlimit ) ; $array = explode ( ' ' , $string ) ; array_pop ( $array ) ; $new_string = implode ( ' ' , $array ) ; return $new_string . '...' ; } else { return $string ; } } $text = "Couper un texte trop long avec une fonction PHP" ; echo cut_string ( $text , 20 ) ; ?>
Après spa compliqué, tu interroge ta base pour récupérer tes données, tu cut_string ton texte de news et tu crées un lien vers affiche_news.php qui affichera toute la news.
@+...
le 18/07/2008 à 09:03
LupusMic
Déconnecté
Développeur récurrent, procédural et relationnel. Caustique soupe-au-lait.
Je proposes les deux versions suivantes :
<?php
function cut_delimited_string ( $string , $size , $delimiter = "\s" ) { if ( $len = strlen ( $string ) > $size ) { $last = $string { $size - 1 } ; while ( $string { $last } != $delimiter and $last > - 1 ) $last -- ; $shorter = $last == - 1 ? substr ( $string , 0 , $size ) : substr ( $string , 0 , $last ) ; } else { $shorter = $string ; } return $shorter ; } ?>
Et si on veut passer par une expression régulière :
<?php
function cut_word_delimited_string ( $string , $size ) { if ( $len = strlen ( $string ) > $size ) { if ( preg_match ( "@^.{," . $size . "}\>@" , $string , $matches ) > 0 ) $shorter = $matches [ 0 ] ; if ( strlen ( $shorter ) == 0 ) $shorter = substr ( $string , 0 , $size ) ; } else { $shorter = $string ; } return $shorter ; } ?>
le 21/07/2008 à 14:56
OKAY, bon ben je vais tester ça merci pour votre aide !
Accès rapide :
PHP / MySQL
HTML / CSS
Javascript
Autres technologies
Le site
Les 3H du PHP
Le bar
Script / Production personnelle
Remonter