| |||||||
| Développement web Pour les webmasters qui utilisent PHP, MySQL, AJAX, CSS, JavaScript, etc. |
| Publicité |
![]() |
| | Outils de la discussion | Modes d'affichage |
| | | #1 |
| Membre d'élite Date d'inscription: 04/09/03 Localisation: Garches
Messages: 1168
Disco: ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 : « $msg »<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>";
}
?> 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/ | ||
| | | |
| Publicité |
| |
| | #2 | |
| Membre confirmé Date d'inscription: 29/05/05 Localisation: San Jose, CA
Messages: 395
Disco: ![]() ![]() | 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("<","<",$content); $content = ereg_replace(">",">",$content); $content = ereg_replace("<br>","<br />",$content); $content = ereg_replace("<br />","<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) | |
| | | |
| | #3 | |
| Membre confirmé Date d'inscription: 29/05/05 Localisation: San Jose, CA
Messages: 395
Disco: ![]() ![]() | 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 ("<", "<", $msg); $msg = str_replace (">", ">", $msg); $msg = stripslashes ($msg); | |
| | | |
| | #4 | |
| Membre d'élite Date d'inscription: 04/09/03 Localisation: Garches
Messages: 1168
Disco: ![]() ![]() ![]() ![]() ![]() ![]() ![]() | ok thanks | |
|
--------------------
Nouveau site : VESPAMAG.COM ainsi que l'adresse du site: http://www.400iso.org/ | ||
| | | |
| | #5 | |
| Modérateur Date d'inscription: 04/01/02 Localisation: Suisse
Messages: 5516
Disco: ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 | ||
| | | |
![]() |
| |
| 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 |