Fricti0n Posted April 17, 2010 Share Posted April 17, 2010 Hi, I'm wondering if someone know how to do this? =] So, I have this inside a XML file 1 0 1 xx xx xx xx xx xx 0 1 xx xx xx xx xx xx 0 1 xx xx xx xx xx xx 0 1 xx xx xx xx xx xx 0 1 xx xx xx xx xx xx 0 1 xx xx xx xx xx xx 0 1 xx xx xx xx xx xx 0 1 xx xx xx xx xx xx 0 1 xx xx xx xx xx xx 0 1 xx xx xx xx xx xx 0 1 0 That is parsed through this function in PHP function sm_str_replace($search, $replace, $subject) { return strtr( $subject, array_combine($search, $replace) ); } $xmlSeatmap = 'modules/seatmap/seatmap.tg11.'.$_GET['zone'].'.xml'; // Defines witch file that should be extracted $countData = file_get_contents($xmlSeatmap); $charCount = strlen($countData); $openSeatmap = fopen($xmlSeatmap, 'r'); $xmlData = fread($openSeatmap, $charCount); fclose($openSeatmap); $search = array('1', '0', ' ', 'x', 's', 'g', 'c', 't'); $replace = array('<tr>', '</tr>', '<td></td>', '<td class="seatmapAvailable" rel="tooltip" alt="Dette setet er ledig (Rad 3 Sete 2)"></td>', '<td class="seatmapScene"></td>', '<td class="seatmapGame"></td>', '<td class="seatmapCreative"></td>', '<td class="seatmapTaken"></td>'); echo '<table class="seatmapContainer">'; echo sm_str_replace($search, $replace, $xmlData); echo '</table>'; It is possible to count X and Y in some way so the first vertical line with X's would be ROW_1 and the second vertical line would be ROW_2, and so on? (The second vertical line is the X's that are on the side with The first vertical line) Thanks for any help! =] rCon^ Link to comment https://forums.phpfreaks.com/topic/198811-count-x-and-y-from-a-file/ Share on other sites More sharing options...
andrewgauger Posted April 17, 2010 Share Posted April 17, 2010 Do it line by line: http://php.net/manual/en/function.fgets.php so you would surround your parsing with: while (!eof($openSeatMap)){ then you could read one line $line=fgets($openSeatMap); do the replace, and perform any mathematics (such as incrementing a counter) Link to comment https://forums.phpfreaks.com/topic/198811-count-x-and-y-from-a-file/#findComment-1043490 Share on other sites More sharing options...
Fricti0n Posted April 17, 2010 Author Share Posted April 17, 2010 Any examples on how to do that? http://php.net/manual/en/function.fgets.php did not give me any help or ideas... I know that for is needed: There is 12 lines in the xml file, so $i = 12 for($i = 12; $i >= 1; $i--) { } It is possible to have a replace array inside a for loop, and decrease the seat number from 10 to 1? the seat on the top is 10, and on the bottom is 1.. rCon^ Link to comment https://forums.phpfreaks.com/topic/198811-count-x-and-y-from-a-file/#findComment-1043939 Share on other sites More sharing options...
Fricti0n Posted April 26, 2010 Author Share Posted April 26, 2010 anyone? sorry for double post, was no edit button :S Link to comment https://forums.phpfreaks.com/topic/198811-count-x-and-y-from-a-file/#findComment-1048284 Share on other sites More sharing options...
ChemicalBliss Posted April 26, 2010 Share Posted April 26, 2010 You want to count the number of x's and y's in the file? All you need to do (if its usually that small a file) is to use: $file = implode("\n",file("test.xml"));?> Then uou can use preg_replace and strlen to count the difference when you replace the character you want to check. $xnum = strlen($file) - strlen(preg_replace("/x/i","",$file)); $ynum = strlen($file) - strlen(preg_replace("/y/i","",$file)); -cb- Link to comment https://forums.phpfreaks.com/topic/198811-count-x-and-y-from-a-file/#findComment-1048308 Share on other sites More sharing options...
andrewgauger Posted April 26, 2010 Share Posted April 26, 2010 Oh, the reason I didn't reply earlier was because my example was for checking horizontal rows, not vertical. I didn't have a solution on how to automate the numbering of instances across a row. Link to comment https://forums.phpfreaks.com/topic/198811-count-x-and-y-from-a-file/#findComment-1048349 Share on other sites More sharing options...
Fricti0n Posted June 10, 2010 Author Share Posted June 10, 2010 I found a solution, 2 for loops was all i needed... And some great math skills -.- But thanks for the help Link to comment https://forums.phpfreaks.com/topic/198811-count-x-and-y-from-a-file/#findComment-1070149 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.