February 28, 200719 yr Ok so ive got a page on my webserver which dynamicly generates statistics in the following style: total=0;good=0;views=0;edits=0;users=0;admins=0;images=0;jobs=0 where 0 is a number between 0 and well.. infinite really but no more than a 7 digit number really. I want to be able to pull the total number from this file and display it on another php page using cURL or file_get_contents but im totally lost by it and cant find a tutorial thats any good for me. I want the number between total= and ;good=....etc anod nothing else so I need to strip all the other stuff. I worked out how to use file_get_contents to get a certain number of characters after a string such as total= but because I cant guarantee what the length of the number is the script varies between 13337 (total=13337;good=....) and 96;go (total=96;good=....) I need the script to start after total= but stop before ;good= Some help would be really appreciated :) Mercifull <3 Suzi "We don't want players to be able to buy their way to success in RuneScape. If we let players start doing this, it devalues RuneScape for others. We feel your status in real-life shouldn't affect your ability to be successful in RuneScape" Jagex 01/04/01 - 02/03/12
February 28, 200719 yr Unless you've got some reason to do it that way - wouldn't it just be easier to use an XML file?
February 28, 200719 yr Author Well im not an expert on this. All i know is that I need to pull off a number from a file this file and display the figure somewhere else. Mercifull <3 Suzi "We don't want players to be able to buy their way to success in RuneScape. If we let players start doing this, it devalues RuneScape for others. We feel your status in real-life shouldn't affect your ability to be successful in RuneScape" Jagex 01/04/01 - 02/03/12
February 28, 200719 yr Ah, the wiki; hrm. Well, you could fetch all the text, explode using ; for the delimeter and str replace a-z and = with null value then you'll be left with your integer values only in the array.
February 28, 200719 yr Author Im not going to pretend i know what im talking about here, Rick, so some links for help would be good lol Mercifull <3 Suzi "We don't want players to be able to buy their way to success in RuneScape. If we let players start doing this, it devalues RuneScape for others. We feel your status in real-life shouldn't affect your ability to be successful in RuneScape" Jagex 01/04/01 - 02/03/12
February 28, 200719 yr Could you use a regex to do it? /total=(\d+);good/ I just posted something! ^_^ to the terrorist...er... kirbybeam.
February 28, 200719 yr <?php $urlofstats = "rawstats.txt"; $rawstats = file_get_contents($urlofstats); $num_values = explode(";", $rawstats); $remove = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","="); foreach($num_values as $x => $value) { $num_values[$x] = str_replace($remove, "", $value); } /* print out the values and [cabbage] */ foreach($num_values as $value) { echo $value." "; } ?>
February 28, 200719 yr Author Thanks to Rick here is the final code I used: <?php $urlofstats = "http://en.battlestarwiki.org/wiki/Special:Statistics?action=raw"; $rawstats = file_get_contents($urlofstats); $num_values = explode(";", $rawstats); $remove = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","="); foreach($num_values as $x => $value) { $num_values[$x] = str_replace($remove, "", $value); } echo $num_values[1]; ?> Mercifull <3 Suzi "We don't want players to be able to buy their way to success in RuneScape. If we let players start doing this, it devalues RuneScape for others. We feel your status in real-life shouldn't affect your ability to be successful in RuneScape" Jagex 01/04/01 - 02/03/12
February 28, 200719 yr Author In action on the front page of the Battlestar Wiki Cheers Rick. Mercifull <3 Suzi "We don't want players to be able to buy their way to success in RuneScape. If we let players start doing this, it devalues RuneScape for others. We feel your status in real-life shouldn't affect your ability to be successful in RuneScape" Jagex 01/04/01 - 02/03/12
Create an account or sign in to comment