liamthebof Posted July 31, 2008 Share Posted July 31, 2008 Ok, I know this is simple as I have dont it before but have long forgot how. SIimplified, I have a test file: information.txt Some useless data in this file Crap here score=174 rolls=8343 other crap total=17 I need to be able to get the value of rolls by going to the 3rd line, and 7th - end of line characters resulting in me attaining the value 8343. I cant count characters from the top of the file as the vlue of score chnage between 2, 3 and 4 figure numbers. Any help is appreciated, Thanks. Link to comment https://forums.phpfreaks.com/topic/117521-solved-2-minute-question/ Share on other sites More sharing options...
samshel Posted July 31, 2008 Share Posted July 31, 2008 <?php $strFile = "information.txt"; $arrLines = file($strFile); echo $arrLines[2]; //will display 3rd line...rolls=8343 echo ereg_replace("rolls=","",$arrLines[2]); //will display 8343 ?> simple enough ? Link to comment https://forums.phpfreaks.com/topic/117521-solved-2-minute-question/#findComment-604467 Share on other sites More sharing options...
liamthebof Posted July 31, 2008 Author Share Posted July 31, 2008 Worked perfectly, thanks. Link to comment https://forums.phpfreaks.com/topic/117521-solved-2-minute-question/#findComment-604474 Share on other sites More sharing options...
liamthebof Posted July 31, 2008 Author Share Posted July 31, 2008 Actually, with further testing I am having problems though your code did work for my example. I will post the actually data I am using: 'http://atlanta.rollinpatrol.com/stats/getstats.php?nickname=[RP]Capop' I am using that external data source and I need to attain the value of Kills. Using <?php $strFile = "http://atlanta.rollinpatrol.com/stats/getstats.php?nickname=[RP]Capop"; $arrLines = file($strFile); echo ereg_replace("Kills=","",$arrLines[6]); //will display 8343 ?> I can see the 2 but I am getting unrequired data from thae source also being achoed. Can you help with this? Link to comment https://forums.phpfreaks.com/topic/117521-solved-2-minute-question/#findComment-604499 Share on other sites More sharing options...
liamthebof Posted July 31, 2008 Author Share Posted July 31, 2008 Firstly, in the above example, ignore the commented 8434 bit; I forgot to remove it. Secondly, the source of data I am using is in PRE tags, I believe this is why the example gave above does not work. Would it be possible to cut out only information that is numeric? But, would that leave the values of the other information? I cannot edit the source but would it be possible to code somethign that firstly converts the source into proper lines information with <BR />'s ect so it could be correctly read by line? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/117521-solved-2-minute-question/#findComment-604550 Share on other sites More sharing options...
liamthebof Posted July 31, 2008 Author Share Posted July 31, 2008 stream_get_contents solved this all. Thanks. Link to comment https://forums.phpfreaks.com/topic/117521-solved-2-minute-question/#findComment-604733 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.