Read from a text file after a specific word
Posted on
16th Feb 2014 07:03 pm by
admin
Hi all.
I have a text file that looks like the one below.
I know how to open the text file but I need to get the php pointer to take a value suck as $username. Once it finds $username, i need it to move to the next following MonthUp"> and then read the number after it and save it to the string $monthup. I will be doing the same for $monthdown and then closing the file.
Eg. If the value is $username, i need to find the first occurance of that username, find the number after MonthUp"> and read it to $monthup, then move to MonthDown"> and then read the number after it to $monthdown.
I will then use php to add the numbers together so that I can show the user when they enter their username into the website, how much they have used for the month.
I am just learning php and all I can find so far from google is reading line-by-line which i want to read after a specific word as I need to do this for a few different files and line by line wont work.
File - stats.cfg - can be renamed to stats.txt easily.
<config>
<list name="UserStats">
<listitem>
<variable name="Id">288A5772-2964-4701-9E66-765F3CECE522</variable>
<variable name="Name">all users</variable>
<variable name="DayUp">32729762</variable>
<variable name="DayDown">336451305</variable>
<variable name="WeekUp">982718994</variable>
<variable name="WeekDown">5711384480</variable>
<variable name="MonthUp">15542938381</variable>
<variable name="MonthDown">106022753555</variable>
<variable name="TotalUp">441879285577</variable>
<variable name="TotalDown">1763579705023</variable>
<variable name="Since">1210849661</variable>
<variable name="Timestamp">1256258234</variable>
<variable name="FullName">all users</variable>
</listitem>
<listitem>
<variable name="Id">807459fd-71a9-467d-bf0c-f0ce98fef937</variable>
<variable name="Name">Administrator</variable>
<variable name="DayUp">0</variable>
<variable name="DayDown">0</variable>
<variable name="WeekUp">0</variable>
<variable name="WeekDown">0</variable>
<variable name="MonthUp">0</variable>
<variable name="MonthDown">0</variable>
<variable name="TotalUp">995621942</variable>
<variable name="TotalDown">6089875753</variable>
<variable name="Since">1210849662</variable>
<variable name="Timestamp">1256224866</variable>
<variable name="FullName"></variable>
</listitem>
<listitem>
<variable name="Id">9cd97dd4-f902-4811-ad05-372658c8ec64</variable>
<variable name="Name">Mathew</variable>
<variable name="DayUp">0</variable>
<variable name="DayDown">0</variable>
<variable name="WeekUp">0</variable>
<variable name="WeekDown">0</variable>
<variable name="MonthUp">36809697</variable>
<variable name="MonthDown">565151504</variable>
<variable name="TotalUp">1739819196</variable>
<variable name="TotalDown">26628701150</variable>
<variable name="Since">1210849662</variable>
<variable name="Timestamp">1256257815</variable>
<variable name="FullName">mathew</variable>
</listitem>
No comments posted yet
Your Answer:
Login to answer
96
40
Other forums
strtotime issue
Hey all,
I'm playing around with some code, and basically the idea is:
Person changes
noob cURL help
I have a pretty basic form that I need to cURL post to a file in my includes folder (includes/login.
New Search Engine
Hey everyone,
I have a ZIP Code Radius search engine already functional. it displays all of t
PHP/Database issue
My friend is helping me make a database where you go to a certain webpage of my site and the page wi
my sql select id and then update problem.
I need to select some auto incremented ids out of a database and then use those id in a where statem
setcookie and isset($_COOKIE(name)) seem very finnicky.
I'm currently playing around with a user system with login and registration. I'm trying to use cooki
preg-match with a string and numbers
Hi, I can't get the expression to work for my preg_match, what I'd like is for it to match the strin
How do I give a developer access to a specific directory and nothing else?
I want to give a develop access to a specific directory and nothing else
I can give them an F
Format String help
I have a textbox where a person enters an application number. the application number is 10 characte
Need help with PHP/MySQL drop down menu
I need help on how I can implement a drop down menu which queries mysql database and output the avai