note 52190 deleted from control-structures.foreach by danbrown
| From: | danbrown@php.net | Date: | Tue, 28 Apr 2009 13:10:49 +0000 |
| Subject: | note 52190 deleted from control-structures.foreach by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153925@lists.php.net to get a copy of this message | ||
Note Submitter: Elvin
----
I wrote this code to add each post from a user to every users' txt file. But it only adds the
message to the last user in users.txt. The reason of that is...(questmark)
<?php
session_start();
header("Cach-control:private");
$name=$_SESSION['name'];
$nameframe=$name.".txt";
$message=$_POST['message'];
$wierdchars = array("\'", "\"", "\\", ":-)",
":-D", ":-p", ":-(", "=p", ">:0",
":-[", ":-/", ":-\\", ":-X", ":-?",
"B-)");
$newchars = array (stripslashes("\'"), stripslashes("\""),
"\\", "<img src='smile.gif'>", "<img
src='opensmile.gif'>", "<img src='tounge.gif'>",
"<img src='sad.gif'>", "<img src='tounge.gif'>",
"<img src='yelling.gif'>", "<img
src='embarrased.gif'>", "<img src='sosoleft.gif'>",
"<img src='sosoright.gif'>", "<img
src='quiet.gif'>", "<img src='confused.gif'>",
"<img src='cool.gif'>");
$newmessage=str_replace($wierdchars, $newchars, $message);
$fontcolor=$_POST['fontcolor'];
$fontsize=$_POST['fontsize'];
$fontface=$_POST['fontface'];
$users=file("users.txt");
foreach($users as $user)
{
$nameframed=$user.".txt";
$thefile=file_get_contents($nameframed);
$file=fopen($nameframed, "w+");
$body=$name."|".$newmessage."\n";
$body2=$body.$thefile;
$write=fwrite($file,$body2);
fclose($file);
}
echo "<html><head><title>Adding info...</title>";
echo "<script>window.location='frame.php';</script>";
echo "</head>";
echo "<!--Removes ads form page</head><body>";
?>