Skip to:
Content
Pages
Categories
Search
Top
Bottom

Anyone here know how to parse files with PHP?

  • I’m just poking around with some log files, and was curious as to how I could parse the data and extract some specific information based on parameters which are determined by my marketing campaign. I suppose I should go to a more specific PHP forum for this, but I thought I’d throw it out here first, just in case anyone had some experience here.

    I’m ultimately thinking of creating a plugin which will analyze CUSTOM data which a user can set to any value they like in the admin panel of either WP or BB.

    I need to read line by line, and extract certain parts of a line, compare some of those parts with other lines to find similarities. I think an example is best:

    88.88.888.88 – – [02/Mar/2007:00:56:38 -0800] “POST /url/of/page/requested/ HTTP/1.1″ 304 256 “/url/of/page/referring/” “Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3″

    This line has a lot of data. All I need is to find out if the url of page requested matches a pre-defined value. Then, I need to find out what the ip address is if it does match the value. I would then need to parse back through the file and pull every line that had a matching ip address.

    Hope this explanation is clear. If anyone has any suggestions, or knows of any simple resources to start this happening, that would be extremely helpful.

    Thanks,

    Ron

    P.S. I’ve read up a little on fget() and file(), but they’re still a little greek to me. A simple example that might work in my case would be most helpful.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Meh, I have little/no experience with handling files myself. Might be easier, though, for you to modify some existing code? There’s already been a lot of very sophisticated work done in statsgathering. I’m thinking of Reinvigorate, for example – not trying to discourage you, just find the most practical solution? I mean, are you in it purely to make the plugin or is there some ulterior motive? :)

    Many, many, many ulterior motives. ;) First of all, this is happening because I can’t seem to find any solution that will search for and filter what <u>I</u> would like it to search for and filter. Instead, it gives the cookie cutter solution.

    I am also on Dreamhost right now, coming from a dedicated hosting environment, (my own server), and since I can’t configure the stats program they have installed, nor can I easily install another of my own, I thought I’d try my hand at learning how to parse files myself.

    So this is partially for education, partially for usefulness, and partially with the hopes of developing something that the gen. public might find helpful.

    Am I wasting my, (and everybody else’s) time?

    You might find this useful. Its Eric Raymond’s article on “smart questions”.


    chrishajer
    Participant

    @chrishajer

    macwise, you might find a php group more helpful for general help with parsing files with PHP, since it’s not purely a bbPress problem.

    Parsing Apache access_log files with PHP

    First Google result for that search.

    More generically, this Google search might help.

    fel64:

    This reinvigorate looks awesome…can’t get in right now, as it’s on a limited beta. However, I’m on the list, and looking forward to trying it out. Thanks

    Ear1grey:

    I know this question is in the wrong place, and sorry if it’s obnoxious. As you guessed, I’m being lazy. I am a little out of my league here in asking for what I have, so I thought I’d get what suggestions I could first from the forum I frequent most. I hope in time you can learn to forgive my impetuous nature. ;)

    chrishajer:

    Thanks for the suggestions, as well as the links. I’ve looked into this a bit, but was really interested in a pre-existing solution I could glean from. I’m not really up on cgi, so a php-only solution is what I’d like to find. (not sure if this exists). I’m pretty good at analyzing something and gleaning what I need from that, so I figured that would be my best shot at getting this thing started.


    ardentfrost
    Member

    @ardentfrost

    Just go to php.net and look it up. They always have good code samples there. I wrote an entire xml parser (first thing I ever wrote in php) 2 years ago from code examples I found on php.net

    macwise, no offence meant, and apologies if any taken. i’m too short on time at the mo and had meant to add a pointer to php.net (which I’ve pointed ppl at previously) before I got sidetracked by a demanding supervisor. ’tis better to have a community where you feel ok to ask – after all, the only dumb questions are those that remain unspoken.

    hi dear, you must go to php.net, they people always have good samples code there. for more detail you must visit http://www.webdesigningcompany.net

    Oh how I love the smell of brand-name luncheon meat in the morning.


    chrishajer
    Participant

    @chrishajer

    mmm potted meat!

Viewing 10 replies - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.