hotwire wrote:

Yeah, that's what's getting me.. Firefox continue to show all matching data even if I only check 1 or 2 boxes out of the 7.. Explorer and Opera shows correctly.. Strange..

Have you run my test script yet?

The next step would be to address the newline problem by running:

foreach ($array as $key => $value)
{
    $array[$key] = rtrim($value);
}

and only then do you use array_diff().

    Yes, I did run the test script and it works Great!

      Ok laserlight,

      You starting to put a smile on my face 🙂 ... Now I see the differences, but my entire data sheet is being erased now :evilgrin:...

      I'm getting excited! The

       foreach ($array as $key => $value)
      {
          $array[$key] = rtrim($value);
      }

      Appears to have made a big difference, if i can stop from erasing the entire data file now..

        Ok laserlight,

        I added the rtim code for the POST array also because without it Explorer was failing and Firefox working.. Talkin about a switch 🙂

        Anyhow here is my code.. It basically lists all messages from the data sheet and place a checkbox near them for deleting.. The echo $val."<br>"; is only temporary for diagnosing the immediate problem..

        <?php
        if (isset($_POST['value']) && is_array($_POST['value']))
        
        {
          $ck=0;
          $x=0;
          $xmsg = $_POST['value'];
          $array = file("data/25k2525.mxg") or exit("Unable to open file!");
          $cx = count($array);
          $cy = count($xmsg);
        
        foreach ($array as $key => $value)
        {
            $array[$key] = rtrim($value);
        }
        
        foreach ($xmsg as $key => $value2)
        {
            $xmsg[$key] = rtrim($value2);
        }
        
          $result = array_diff($array, $xmsg);
        
        	$fp = fopen( "data/25k2525.mxg" , "w" );
            foreach($result as $val)
            {
        	echo $val."<br>";
        	fwrite($fp, $val)."<br />";
            }
        	fclose($fp);
            }
        
        
        $array= file("data/25k2525.mxg") or exit("No Messages Available At This Time!");
        ?>
        <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
        
        <?
        echo "<table bgcolor='#000033' border='5' width='50' cellpadding='2' cellspacing='0'>";    echo "<tr><td>";
             echo "<table bgcolor='#555555' border='1' width='75' cellpadding='5' cellspacing='0'>";
             echo "<tr><th align='left'>";
             echo "<font face='arial' size='3' color='white'>Welcome To Your Message Box";
             echo "</th></tr>";
             echo "<tr><td bgcolor='#F3ECE0'>";
             echo "<font color='green' face='arial'><i>Viewed</i></font>&nbsp;&nbsp;<font face='arial' size='2' color='#000000'>=&nbsp;Messages You Already Read.</font>&nbsp;&nbsp;&nbsp;&nbsp;<font color='#FF0000' face='arial'><i>Unread</i></font>&nbsp;&nbsp;<font face='arial' size='2' color='#000000'>=&nbsp;Messages You Have Not Read";
            echo "</td></tr>";
            echo "<tr><td nowrap>";
            echo "<div style='background-color:#FFFFEC; width:555px; height:150px; overflow:auto; padding-left:8px; padding-top:5px'>";
        	foreach($array as $val)
            {
        	$rdid = substr($val, 0, strpos($val, "~"));
        	$prdex = explode("~", $val);
        	$time = $prdex[0]; // message time
            $date = $prdex[1];  // message date
        	$sender = ($prdex[2]); // messgae sender
        	$msg=($prdex[3]); // message contents
        	$viewed=($prdex[4]); // message viewed status
        	$a=2;
            $ftime = date("g:i A", $time);
            $fmsg = "Message From: ".$sender." On ".$date." At ".$ftime."<br />";
        
        if ($viewed==1)
        {
        echo "<input type='checkbox' value='".$time."~".$date."~".$sender."~".$msg."~".$viewed."' name='value[]'><font color='green' size='2' face='arial'><i>Viewed</i>&nbsp;&nbsp;<a href='showmsg.php?msg=".$msg."&id=".$time."&date=".$date."&sender=".$sender."&viewed=".$viewed."' target='items' class='but1'>".$fmsg."</a>";
        }
        if ($viewed==0)
        {
        echo "<input type='checkbox' value='".$time."~".$date."~".$sender."~".$msg."~".$viewed."' name='value[]'><font color='red' size='2' face='arial'><i>Unread</i>&nbsp;&nbsp;<a href='showmsg.php?msg=".$msg."&id=".$time."&date=".$date."&sender=".$sender."&viewed=".$viewed."' target='items' class='but2'>".$fmsg."</a>";
        }
        }
        echo "</div>";
        echo "</td></tr>";
        echo "<tr><td>";
        echo "<input type='submit' value='Delete Selected Messages' />";
        echo "</td></tr>";
        echo "<tr><td align='center' bgcolor='#333333'>";
        echo "<iframe name='items' width='550' height='220' src='showmsg.php' frameborder='1'>Your browser does not support inline frames or is currently configured not to display inline frames.</iframe>";
        echo "</td></tr>";
        echo "<tr><td height='30'>";
        echo "</td></tr>";
        echo "</table>";
        echo "</tr></td></table>";
        ?>
        
        <HTML>
        <HEAD>
        <style>
         .but1{
           color:#000000;
           font-size: 12px;
           text-decoration: none;
           margin-top:2px;
        	}
        .but1:link {
        	color:#000000;
        	}
        .but1:visited {
        	color:#0066FF;
        	}
        .but1:hover {
        	color:#FF0000;
        	}
        .but1:active {
        	color:#0066FF;
        }
        
        .but2{
           color:#0066FF;
           font-size: 12px;
           font-weight: bold;
           text-decoration: none;
           margin-top:2px;
        	}
        .but2:link {
        	color:#0066FF;
        	}
        .but2:visited {
        	color:#0066FF;
        	}
        .but2:hover {
        	color:#FF0000;
        	}
        .but2:active {
        	color:#0066FF;
        }
        </style>
        
        
        </HEAD>
        </HTML>

        Hope this helps.. And Thanks for your time..

          Another change that you should make is:

          fwrite($fp, $val)."<br />";

          to:

          fwrite($fp, $val . "\n");

            Ok thanks,

            I did not know the thread went to another page.. Crazy me 🙂 sorry for the delay..

              AMAZING! Now the data is writing to the file Again! Just by changing what you told me:

              fwrite($fp, $val . "\n");

              Now Explore, Opera, and Firefox is writing Correctly! 😃

              YOU ARE AMAZING laserlight! You have helped me before, and I Greatly Appreciate It!

              You are certainly my Genius when it comes to PHP 🙂..

              What was the problem with Firefox and that rtrim thing?

                hotwire wrote:

                What was the problem with Firefox and that rtrim thing?

                I am not sure, actually. Firefox appears to have been sending the form data with the newlines removed, while MSIE and Opera did not (at least from what I gather you wrote the newlines along with the rest of the data into the form element values). The final fix involved re-inserting the newlines when the file was being written back.

                Oh, and remember to mark this thread as resolved (if it is) using the thread tools 🙂

                  Gotcha, Never thought returns would be so sensative when it come to arrays and browsers.. Gee ..

                  Well it appears that the writing is performing ok now with the popular browsers, do you think it should be safe to use the rtrim for all future projects using arrays as this?

                    hotwire wrote:

                    Well it appears that the writing is performing ok now with the popular browsers, do you think it should be safe to use the rtrim for all future projects using arrays as this?

                    It depends on the situation, so you should not blindly use a function just because it has worked before. In this case it is useful because file() leaves the newline sequence at the end of each line.

                      Ok thanks laserlight for your help, I will consider this as resolved as it stands.. It appears to be working now.. Thanks to your help.. I appreciate it!

                        Write a Reply...