"...Remember being a youngster, mom or dad telling you "close the door"? Well the same applies to HTML ...."

Go Back   Webmaster Forums > Code Forum > PHP Forum

Reply
 
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.
Old 11-06-2009, 05:51 PM   #1
hottac
New Member
 
Join Date: Nov 2009
Webmaster Discussions: 3
Rep Power: 6
hottac is on a distinguished road
extracting comments

Hi all, I know this probably an elementary question to some of you, but I'm just learning php myself.

I was wondering if someone could help me with a script to extract a comment line from a text file. I have alot of txt files handed to me at work and all of them have comments that I need to extract and combine into one txt file. Lets say that one txt file has bunch of sentence in it but usually at the end, it'd have a "Comment: brad does a great job of helping me" Is there a way where I could just drop all of the text files into a folder and let php extract all the comments and combined into one file? Thank you and any help would be very appreciated



Last edited by hottac; 11-06-2009 at 07:53 PM.
hottac is offline   Reply With Quote
Old 11-20-2009, 05:56 PM   #2
jthayne
 
jthayne's Avatar
 
Join Date: Aug 2008
Location: Texas
Webmaster Discussions: 501
Rep Power: 21
jthayne is the hardest working person in the biz.jthayne is the hardest working person in the biz.jthayne is the hardest working person in the biz.jthayne is the hardest working person in the biz.
Re: extracting comments from text file

Are the text files always formatted the same way? For example, are the comments always last and do they always begin with "Comment:"?
__________________
Be sure to click the reputation icon to give rep to the person who helped you.
For web design/development services, check Silentium Designs.
jthayne is offline   Reply With Quote
Old 11-21-2009, 04:10 AM   #3
hottac
New Member
 
Join Date: Nov 2009
Webmaster Discussions: 3
Rep Power: 6
hottac is on a distinguished road
Re: extracting comments from text file

yes, the text files are always formatted the same. For example:

something line
something line
Comment:brad does a great job of helping me and it can go on and wrap itself
something line

Thanks
hottac is offline   Reply With Quote
Old 11-23-2009, 10:51 AM   #4
jthayne
 
jthayne's Avatar
 
Join Date: Aug 2008
Location: Texas
Webmaster Discussions: 501
Rep Power: 21
jthayne is the hardest working person in the biz.jthayne is the hardest working person in the biz.jthayne is the hardest working person in the biz.jthayne is the hardest working person in the biz.
Re: extracting comments from text file

Use the following code, and modify it to do what you need. I have already modified it some for you.

PHP Code:
<?php
$handle 
= @fopen("/tmp/inputfile.txt""r");
if (
$handle) {
    while (!
feof($handle)) {
        
$buffer fgets($handle);
        if (
strtolower(substr($buffer08)) == "comments") {
            echo 
$buffer;
        }
    }
    
fclose($handle);
}
?>
You can also check php.net for more information on the above functions
__________________
Be sure to click the reputation icon to give rep to the person who helped you.
For web design/development services, check Silentium Designs.
jthayne is offline   Reply With Quote
Old 11-25-2009, 04:01 AM   #5
hottac
New Member
 
Join Date: Nov 2009
Webmaster Discussions: 3
Rep Power: 6
hottac is on a distinguished road
Re: extracting comments from text file

oh nice jthayne, I will give it a try during my time off this holiday. Lets say if I need it to modify where the script looks inside a folder and open all the text files in the folder and extract any comments, will that be hard to integrate into this script you made? Thank you so much for your time and if I don't hear from you, have a nice thanksgiving.
hottac is offline   Reply With Quote
Reply

Bookmarks

Tags
comments, extracting, file, text

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Webmaster Discussions
Thread Webmaster Discussion Starter Forum Replies Last Post
Extracting Form Field Values ChubChub HTML Forum 0 10-10-2007 03:17 PM
Writing to text file problem long123 CGI Perl Forum 5 08-02-2005 08:33 AM
displaying text in on a page from file... robbyvegas HTML Forum 1 12-18-2003 01:23 PM
reading from text file to textarea using vbscript vennly Website Scripts Forum 0 12-05-2003 03:03 AM
Email Text File ScottB CGI Perl Forum 1 12-04-2001 02:08 PM


All times are GMT -5. The time now is 08:54 PM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.