Précédent   Forum Mac > Création sur Mac - iLife et Pro > Développement web



Développement web Pour les webmasters qui utilisent PHP, MySQL, AJAX, CSS, JavaScript, etc.

Publicité

Réponse
 
Outils de la discussion Modes d'affichage
Vieux 14/01/2006, 00h56
Question script livre d'or
  #1
Membre d'élite
 
Avatar de mistertitan
 
Date d'inscription: 04/09/03
Localisation: Garches
Messages: 1168
Disco: mistertitan est un habitué qui fait la bise au DJmistertitan est un habitué qui fait la bise au DJmistertitan est un habitué qui fait la bise au DJmistertitan est un habitué qui fait la bise au DJmistertitan est un habitué qui fait la bise au DJmistertitan est un habitué qui fait la bise au DJmistertitan est un habitué qui fait la bise au DJ
j'ai une petite requète avec mon script livre d'or

Code:
        <form action="livre.php3"
              name="messager"
              method="post">
          Nom :
          <br />
          <input type="text"
                name="person"
                size="50" />
          <br />
          Message :
          <br />
          <textarea name="message"
                cols="50">
</textarea>
          <br />
          <input name="submit"
                type="submit"
                value="Ecrire"
                border="0" /><input name="reset"
                type="reset"
                value="Annuler"
                border="0" />
        </form><?
        #       the $chat_file_ok is a txt file (or whatever else) I use for messages storage
        $chat_file_ok = "../msg.txt";

        #       $chat_lenght is the number of messages displayed
        $chat_lenght = 50;

        /*      $max_file_size is the maximum file size the msg.txt file can reach
                assuming that any chatter doesn't write a message longer than
                $max_single_msg_lenght (this case: 100,000 bytes = 100Kb)               */
        $max_single_msg_lenght = 10000;
        $max_file_size = $chat_lenght * $max_single_msg_lenght;

        # check if file size is over maximum    (set with $max_file_size )
        $file_size= filesize($chat_file);

        /*      if file size is more than allowed then
                                reads last $chat_lenght messages (last lines of msg.txt file)
                                and stores them in $lines array
                                then deletes the "old" msg.txt file and create a new msg.txt
                                pushing the "old" messages stored in $lines array into the
                                "new" msg.txt file using $msg_old.
                        Note: this is done in order to avoid huge msg.txt file size.            */
                                
        if ($file_size > $max_file_size) {
                # reads file and stores each line $lines array elements
                $lines = file($chat_file_ok);
                # get number of lines
                $a = count($lines);
                $u = $a - $chat_lenght;
                for($i = $a; $i >= $u ;$i--)
                {
                        $msg_old = $lines[$i] . $msg_old;
                }
                $deleted = unlink($chat_file_ok);
                $fp = fopen($chat_file_ok, "a+");
                $fw = fwrite($fp, $msg_old);
                fclose($fp);
        }

        /* the following is because every message has to be
         placed into one single line in the msg.txt file.
         You can render \n (new lines) with "<br>" html tag anyway.     */

        $msg = str_replace ("\n"," ", $message);

        /*      if the user writes something...
                the new message is appended to the msg.txt file
                REMEMBER: the message is appended, hence, if
                you want the last message to be displayed as the
                first one, you have to
                        1. store the lines (messages) into the array
                        2. read the array in reverse order
                        3. post the messages in the output file (the chat)
                        
         I added these three lines in order to avoid buggy html code and slashes        */
        $msg = str_replace ("\n"," ", $message);
        $msg = str_replace ("<", " ", $msg);
        $msg = str_replace (">", " ", $msg);
        $msg = stripslashes ($msg);




        if ($msg != ""){
        $fp = fopen($chat_file_ok, "a+");
        $fw = fwrite($fp, "\n<small><small>".date("d/m/Y H")."h".date("i")." </small></small><br>- $person : &laquo; $msg &raquo;<br><br>");
        fclose($fp);
        }

        $lines = file($chat_file_ok);
        $a = count($lines);

        $u = $a - $chat_lenght;

        #       reads the array in reverse order and outputs to chat
        for($i = $a; $i >= $u ;$i--){
                        echo $lines[$i].""; # pour ajouter qqchose entre les lignes : echo $lines[$i]."<hr>";
                }

        ?>
C'est un pote que je ne vois plus qui me l'avais filé.
et quand on écrit un message sur 2 lignes, il remet tout sur une seule ligne.
J'aimerais savoir qi quelqu'un saurait comment le modifier pour que un saut a la ligne se transforme en <br>
--------------------
Nouveau site : VESPAMAG.COM

ainsi que l'adresse du site: http://www.400iso.org/
mistertitan est déconnecté   Réponse avec citation
Publicité
Vieux 14/01/2006, 01h14   #2
Membre confirmé
 
Avatar de canibal
 
Date d'inscription: 29/05/05
Localisation: San Jose, CA
Messages: 395
Disco: canibal s'approche du bar et commande un Ginicanibal s'approche du bar et commande un Gini
Arf bon j'ai pas la motivation de m'attaquer à ton code le principe est d'utiliser la fonction nl2br()

Moi par exemple lorsque j'ai un message je fais deux petite chose qu'on pourrait penser inutiles mais bon ça sert en fait

Soit la fonction :


function securehtml($content)
{
$content = ereg_replace("<","&lt;",$content);
$content = ereg_replace(">","&gt;",$content);
$content = ereg_replace("&lt;br&gt;","<br />",$content);
$content = ereg_replace("&lt;br /&gt;","<br />",$content);
return $content;
}

qui évite les codes html dans les messages

et derrière


$message= nl2br(securehtml($message));

qui transforme tes \n en <br /> et supprime tout code autre ne html (pour l'html t'es pas obligé mais c'est plus propre)
canibal est déconnecté   Réponse avec citation
Vieux 14/01/2006, 01h18   #3
Membre confirmé
 
Avatar de canibal
 
Date d'inscription: 29/05/05
Localisation: San Jose, CA
Messages: 395
Disco: canibal s'approche du bar et commande un Ginicanibal s'approche du bar et commande un Gini
Bon il est tard mais je me suis motivé poiur regarder :

3. post the messages in the output file (the chat)

I added these three lines in order to avoid buggy html code and slashes */
$msg = str_replace ("\n"," ", $message);
$msg = str_replace ("<", " ", $msg);
$msg = str_replace (">", " ", $msg);
$msg = stripslashes ($msg);

Ici à la place tu mets
$msg = str_replace ("\n","<br />", $message);
$msg = str_replace ("<", "&lt;", $msg);
$msg = str_replace (">", "
&gt;", $msg);
$msg = stripslashes ($msg);
canibal est déconnecté   Réponse avec citation
Vieux 14/01/2006, 02h44   #4
Membre d'élite
 
Avatar de mistertitan
 
Date d'inscription: 04/09/03
Localisation: Garches
Messages: 1168
Disco: mistertitan est un habitué qui fait la bise au DJmistertitan est un habitué qui fait la bise au DJmistertitan est un habitué qui fait la bise au DJmistertitan est un habitué qui fait la bise au DJmistertitan est un habitué qui fait la bise au DJmistertitan est un habitué qui fait la bise au DJmistertitan est un habitué qui fait la bise au DJ
ok thanks
--------------------
Nouveau site : VESPAMAG.COM

ainsi que l'adresse du site: http://www.400iso.org/
mistertitan est déconnecté   Réponse avec citation
Vieux 14/01/2006, 08h14   #5
Modérateur
 
Avatar de molgow
 
Date d'inscription: 04/01/02
Localisation: Suisse
Messages: 5516
Disco: molgow mixe pour MacGeneration au Pachamolgow mixe pour MacGeneration au Pachamolgow mixe pour MacGeneration au Pachamolgow mixe pour MacGeneration au Pachamolgow mixe pour MacGeneration au Pachamolgow mixe pour MacGeneration au Pachamolgow mixe pour MacGeneration au Pachamolgow mixe pour MacGeneration au Pachamolgow mixe pour MacGeneration au Pachamolgow mixe pour MacGeneration au Pachamolgow mixe pour MacGeneration au Pacha
Il me semble que ça serait mieux d'utiliser une fonction inclue dans PHP pour traduire certains caractères utilisés en HTML. Comme par exemple, la fonction htmlentities().
--------------------
L'éthique, ce mot-lessive, est utilisé à tout instant pour laver les consciences sans frotter. Corinne Maier
molgow est déconnecté   Réponse avec citation

Réponse
Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are non
Pingbacks are non
Refbacks are non





Utilisateurs regardant la discussion actuelle : 1 (0 membre(s) et 1 invité(s))
 
Outils de la discussion
Modes d'affichage

Discussions similaires
Discussion Auteur Forum Réponses Dernier message
Rapidweaver et livre d'or ? MACMIC Développement web 9 07/01/2012 14h41
livre d'or avec iWeb M. Hulot Forum iWeb 12 02/08/2009 19h11
Livre d'or spammé Alumineux Internet et réseau 6 03/03/2007 21h20
Faire un livre d'or erge Développement web 2 31/01/2006 21h44
Intégration livre d'or fabriced Développement web 0 24/07/2002 21h09


Fuseau horaire GMT +1. Il est actuellement 02h03.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.0
Version française #20 par l'association vBulletin francophone
CNIL N°1009176viagra