-
Posts
9 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by Monckey100
-
-
perfect!! How would I go about reading the file now? I understand I wouldn't just place an explode...$line .= $matrix[$i][$x] . ($x < (sizeOf($matrix[0]) -1) ? "," : "\r\n") ;
try like this with -1
-
$line .= $matrix[$i][$x] . ($x < sizeOf($matrix[0]) ? "," : "\r\n") ; // credits to astralaaron
still nothing :|
-
okay great, I opened it in wordpad,notepad and microsoft word, the \n's don't seem to be registeringIf you look at the page source code it will look like the map grid, the \n doesn't show on the page edit: to load it back into the array you can just do explode("\n",$lines), and then explode(",",$line) -
It doesn't seem to parse as intended, instead it goes xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxinstead ofxxxxxxxxxxxxxxxxxxxxxxxx but I guess it's not that big of a deal, any idea how I would go about reparsing it back into the matrix?I did this test and the array loops out like you are trying to do. Make sure that $_POST['mapname'] is set so it runs that part of the code.<?php $matrix = array( array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01), array(10, 10, 01, 03, 04, 01, 03, 05, 02, 01) ); for($i = 0; $i < sizeOf($matrix); $i++) {$line = "";$size = sizeOf($matrix[$i]); for($x = 0; $x < $size; $x++) { $line .= $matrix[$i][$x] . ($x < ($size-1) ? "," : "\n") ; // edit 2 } echo($line);}?>
-
$matrix[10][10] = "hi";$file = fopen('file.txt', 'w');if(isset($_POST['mapname'])){for($i = 0; $i < sizeOf($matrix); $i++) {$line = ""; for($x = 0; $x < sizeOf($matrix[0]); $x++) { $line .= $matrix[$i][$x] . ($x < sizeOf($matrix[0]) ? "," : "\n") ; // edit 2 } fwrite($file, $line);}}
The code looks like this but it yields 0 bytes the text file....here's the rest of the code that is being used to put values into the matrix.
<form method="post" action="<?php echo $PHP_SELF;?>"><table><tr><td>Item tree:</td><td><INPUT TYPE="Text" name="items"></td></tr><tr><td>Map Name:</td><td><INPUT TYPE="Text" name="mapname"></td><td><INPUT TYPE="submit" value="save"/></td></tr></table><table border=1 width=100%><?php$matrix[10][10] = "hi";$file = fopen('file.txt', 'w');if(isset($_POST['mapname'])){for($i = 0; $i < sizeOf($matrix); $i++) {$line = ""; for($x = 0; $x < sizeOf($matrix[0]); $x++) { $line .= $matrix[$i][$x] . ($x < sizeOf($matrix[0]) ? "," : "\n") ; // edit 2 } fwrite($file, $line);}}for ($i = 0; $i <= 10; $i++){echo'<tr>';for($r =0; $r <= 10; $r++){ echo'<td><INPUT TYPE="Text" name="$matrix[$i][$r]" value="empty" size="10%"></td>';}echo'</tr>';}?>
-
sha1 usage
in PHP
I'm surprised no one mentioned this but you can use sha1 to compare file sizes and even do some sort of spider crawl on your site to compare for duplicate images.also if you sha1 the users, usernames then you wouldn't be able to do simple calls like "Welcome Monckey100!, settings, about" Etc
-
Minor detail but spacing always helps you quickly read through code if tabbing is not available
-
so I've figured out how to read an array and place it into a file with a single array...$matrix[10] and have it save onto a file all of the data with a new line per databut it gets kind of unnecessary and messy, however it's still readable. When it comes to $matrix[10][10] it becomes UNREADABLE, basically what I do isrun it through [0][0-10] and then [1][0-10] etc until its done all the values which isfine because its reparsable but for convenience I want it so I can quickly edit the numberson the txt file. ex:1,1,2,3,5,6,7,2,4,62,4,5,6,7,8,5,3,1,3 instead of112356724624...etc I want some form of code that can easily parse onto a text file and read it, I haven't posted my code because I like to implement the code in myself to have it work efficiently Here's what I have tried which has...failed..
$matrix [10][10];if(isset($_POST['mapname'])){$file = fopen('file.txt', 'w');foreach($matrix as &$array){fwrite($file, $array ."\n". '');}}
P.s. Excuse my informality, I've been quite stomped and I apologize for the lack of an introduction thread. Edit: Changed the first line, it was creating a syntax error
Saving double array to a file? $matrix[10][10]
in PHP
Posted