jege Posted August 6, 2012 Share Posted August 6, 2012 Hey. I got a file like this: #First line some random comment someplayername=Stealing andanother=\u00A7cAsshat The filetype is .properties So, how could I read the file, so the player name, the word before the "=" would be stored somewhere and displayed, and the reason, which is after = would be stored and displayd on the page. That's a banlist of a Minecraft server, so It would be a table like "Player name: john" Reason: "Asshat" also, as you can see the Asshat has "\u00A7c" i'm not sure what "language" or "markup" it is, but i know it stands for light red color. So the script should ignore the light red tags if possible. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/266729-read-a-file-get-specific-content-from-it/ Share on other sites More sharing options...
scootstah Posted August 6, 2012 Share Posted August 6, 2012 You'd probably have to parse it with regular expressions. Or, depending on the structure, you might be able to use something like strtok. Or a combination of the two. Quote Link to comment https://forums.phpfreaks.com/topic/266729-read-a-file-get-specific-content-from-it/#findComment-1367134 Share on other sites More sharing options...
ManiacDan Posted August 6, 2012 Share Posted August 6, 2012 Or you could parse this INI file with parse_ini_file Quote Link to comment https://forums.phpfreaks.com/topic/266729-read-a-file-get-specific-content-from-it/#findComment-1367136 Share on other sites More sharing options...
redarrow Posted August 6, 2012 Share Posted August 6, 2012 or try something like this (example only.) <?php $content = file_get_contents('http://www.sparkfun.com/commerce/product_info.php?products_id=9279'); preg_match('#<tr><th>(.*)</th> <td><b>price</b></td></tr>#', $content, $match); $price = $match[1]; preg_match('#<input type="hidden" name="quantity_on_hand" value="(.*?)">#', $content, $match); $in_stock = $match[1]; echo "Price: $price - Availability: $in_stock\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/266729-read-a-file-get-specific-content-from-it/#findComment-1367138 Share on other sites More sharing options...
ManiacDan Posted August 6, 2012 Share Posted August 6, 2012 or try something like this (example only.) How is this at all relevant to anything we're discussing? This parses two distinct values from an HTML document. The question is on parsing an entire document formatted like an INI file. Quote Link to comment https://forums.phpfreaks.com/topic/266729-read-a-file-get-specific-content-from-it/#findComment-1367192 Share on other sites More sharing options...
jege Posted August 13, 2012 Author Share Posted August 13, 2012 Ok, this is my code: $ini_array = parse_ini_file("$file"); foreach($ini_array as $bans){ echo "<tr>"; echo "<td><i should get the username here></td>"; echo "<td>$bans</td>"; echo "</tr>"; } I'm totally terrible with arrays, how can I get the username there? Heres a piece of the array: Array ( [gamegazelle] => Grief [JamesRB] => Grief) Quote Link to comment https://forums.phpfreaks.com/topic/266729-read-a-file-get-specific-content-from-it/#findComment-1368924 Share on other sites More sharing options...
ManiacDan Posted August 13, 2012 Share Posted August 13, 2012 The variable name is the key: foreach ( $ini_array as $var => $val ) { echo "The INI value of {$var} is {$val}<br />\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/266729-read-a-file-get-specific-content-from-it/#findComment-1368947 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.