Re: [PHP] Text file
alantodd wrote: What would be the easiest way to open a text file, remove a line if the line begins with a word from an array of words (there are 5 words I will be looking for) then write that back to the text file with everything removed ?php $lookfor = array('one','two','three','four','five'); $pattern = implode('|',$lookfor); $filedata = file('yourfile.txt'); foreach($filedata as $key = $line) { if(preg_match(/^($pattern)/i,$line)) { unset($filedata[$key]); } } $newfiledata = implode(\n,$filedata); $fp = fopen('yourfile.txt','w'); fwrite($fp,$newfiledata); fclose($fp); ? Untested, but something like that. Read file into an array, loop through each line trying to match word at beginning. If there's a match, remove line, then write new data at the end. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Text file wont' have newlines?
Ashwin Purohit [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi everybody, I have this script in a file that allows users to upload files, and I want to know who submitted what so I write $userfile_name and $credit1(their name) to CREDIT.txt in the same directory like so : $credit = $userfile_name.': '.$credit1.\n; $fp = fopen('CREDIT.txt','a'); fwrite($fp, $credit); fclose($fp); But every new submission ends up on the same line, there is never a line break in the text. Any suggestions? Try \r\n or chr(10): $credit = $userfile_name.': '.$credit1.\r\n; $credit = $userfile_name.': '.$credit1.chr(10); Regards, Torsten -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Text file wont' have newlines?
Needs a new line and return. fwrite($fp, ($credit . \n\r) ); Hi everybody, I have this script in a file that allows users to upload files, and I want to know who submitted what so I write $userfile_name and $credit1(their name) to CREDIT.txt in the same directory like so : $credit = $userfile_name.': '.$credit1.\n; $fp = fopen('CREDIT.txt','a'); fwrite($fp, $credit); fclose($fp); But every new submission ends up on the same line, there is never a line break in the text. Any suggestions? Thanks, AMP _ FREE pop-up blocking with the new MSN Toolbar get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Text file wont' have newlines?
Ok, thanks much! It works now. Needs a new line and return. fwrite($fp, ($credit . \n\r) ); Hi everybody, I have this script in a file that allows users to upload files, and I want to know who submitted what so I write $userfile_name and $credit1(their name) to CREDIT.txt in the same directory like so : $credit = $userfile_name.': '.$credit1.\n; $fp = fopen('CREDIT.txt','a'); fwrite($fp, $credit); fclose($fp); But every new submission ends up on the same line, there is never a line break in the text. Any suggestions? Thanks, AMP _ FREE pop-up blocking with the new MSN Toolbar get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Stop worrying about overloading your inbox - get MSN Hotmail Extra Storage! http://join.msn.click-url.com/go/onm00200362ave/direct/01/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Text file manipulation question.
-Original Message- From: Lloyd Bayley [mailto:[EMAIL PROTECTED] Sent: 15 July 2003 00:21 I'm still in the learning stages of PHP and require some help with a small problem. I need to take a text file which looks like this (and no I can't get it output in CSV - damn and blast!) user1 26:48:59 6 logins 4:28:09 hrs/login user2 19:07:50 33 logins 0:34:46 hrs/login user3 12:12:04 18 logins 0:40:40 hrs/login user49:48:58 9 logins 1:05:26 hrs/login What I want to do (in PHP) is read the list in and search for a username, then display the associated statistics for that user. I'm hoping to get the logistics right first before wrapping it in a form. Breaking it up into a list works well, except for the fact that the spaces between elements are not necessarily the same. (bother!) Any suggestions, like for example to convert a string of spaces (greater than 1) to a comma perhaps to facilitate easier list building? Try preg_split('/ +/', $line); to get an array of the values on a single line. You could easily do this to each line of the file and build an array of arrays to give you the full data structure. With a bit of judicious manipulation, you could even use the usernames as the key of the outer array. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Text file manipulation question.
Lloyd Bayley [EMAIL PROTECTED] wrote: Greetings All! I'm still in the learning stages of PHP and require some help with a small problem. I need to take a text file which looks like this (and no I can't get it output in CSV - damn and blast!) user1 26:48:59 6 logins 4:28:09 hrs/login user2 19:07:50 33 logins 0:34:46 hrs/login user3 12:12:04 18 logins 0:40:40 hrs/login user49:48:58 9 logins 1:05:26 hrs/login What I want to do (in PHP) is read the list in and search for a username, then display the associated statistics for that user. I'm hoping to get the logistics right first before wrapping it in a form. Breaking it up into a list works well, except for the fact that the spaces between elements are not necessarily the same. (bother!) Any suggestions, like for example to convert a string of spaces (greater than 1) to a comma perhaps to facilitate easier list building? Assuming you read each line of the file into a variable called $line: //replace more than one space to a comma $newline = ereg_replace(' +', ',', $line); Translates: user1 26:48:59 6 logins 4:28:09 hrs/login To: user1,26:48:59,6 logins,4:28:09 hrs/login Cheers, Lloyd. :-) PS: I'm an old Coldfusion programmer who has seen the lightso I have the logics but can't translate it to PHP...therefore, I'm here! :-) Good to hear that! HTH, Curt -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Text file manipulation question.
Thankyou! That works a treat! Lloyd. :-) At 11:36 PM 14/07/2003 +, you wrote: Lloyd Bayley [EMAIL PROTECTED] wrote: Greetings All! I'm still in the learning stages of PHP and require some help with a small problem. I need to take a text file which looks like this (and no I can't get it output in CSV - damn and blast!) user1 26:48:59 6 logins 4:28:09 hrs/login user2 19:07:50 33 logins 0:34:46 hrs/login user3 12:12:04 18 logins 0:40:40 hrs/login user49:48:58 9 logins 1:05:26 hrs/login What I want to do (in PHP) is read the list in and search for a username, then display the associated statistics for that user. I'm hoping to get the logistics right first before wrapping it in a form. Breaking it up into a list works well, except for the fact that the spaces between elements are not necessarily the same. (bother!) Any suggestions, like for example to convert a string of spaces (greater than 1) to a comma perhaps to facilitate easier list building? Assuming you read each line of the file into a variable called $line: //replace more than one space to a comma $newline = ereg_replace(' +', ',', $line); Translates: user1 26:48:59 6 logins 4:28:09 hrs/login To: user1,26:48:59,6 logins,4:28:09 hrs/login Cheers, Lloyd. :-) PS: I'm an old Coldfusion programmer who has seen the lightso I have the logics but can't translate it to PHP...therefore, I'm here! :-) Good to hear that! HTH, Curt -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Text File open and display
You get a file to an array of lines with file(). Example: ? $myFile = file(text_file.txt); // Now $myFile is an array looking like // [0] = row 1; // [1] = row 2; // [2] = row 3; // . for ($i = 0; $i count($myFile); $i++) { print Row .($i+1).: .$myFile[$i]; }; ? Niklas -Original Message- From: Chris Blake [mailto:[EMAIL PROTECTED] Sent: 3. maaliskuuta 2003 10:58 To: [EMAIL PROTECTED] Subject: [PHP] Text File open and display Greetings learned PHP(eople), There have been a number of postings recently on opening and reading files, and whilst I have read `em all I fail to make sense of it all. Basicaly...I have a text file with entries in it...I wish to display the contents of this file line by line in an HTML table : At present all I get is a table with 1 row and all the text in it in a large messy blob. = html body ?php $handle = fopen(fopen.txt,r); echo 'table border=1'.\n; echo ' tr'.\n; echo ' td width=15%bFile Entries/b/td'.\n; echo ' /tr'.\n.\n; // //For each line in the file // while (fpassthru($handle)); //{ //Print them out to Table- echo 'tr'.\n; echo ' td width=15%font size=2'; echo fpassthru($handle); echo '/td/tr'. \n; //} echo '/table'; //fclose($handle); ? /body /html = I have commented out those lines which fail and am stuck as to what the correct syntax should be. I have read up on nl2br,fgets and other posts on php.net, but ..harump Thanks -- Chris Blake Office : (011) 782-0840 Cell : 083 985 0379 It is reported that somewhere in the world, every 15 seconds, a woman gives birth to a child. She must be found and stopped. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ### This message has been scanned by F-Secure Anti-Virus for Internet Mail. For more information, connect to http://www.F-Secure.com/ ### This message has been scanned by F-Secure Anti-Virus for Internet Mail. For more information, connect to http://www.F-Secure.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Text File open and display
Muchos grassy arse...works perfectly On Mon, 2003-03-03 at 11:06, Niklas Lampén wrote: You get a file to an array of lines with file(). Example: ? $myFile = file(text_file.txt); // Now $myFile is an array looking like // [0] = row 1; // [1] = row 2; // [2] = row 3; // . for ($i = 0; $i count($myFile); $i++) { print Row .($i+1).: .$myFile[$i]; }; ? Niklas -Original Message- From: Chris Blake [mailto:[EMAIL PROTECTED] Sent: 3. maaliskuuta 2003 10:58 To: [EMAIL PROTECTED] Subject: [PHP] Text File open and display Greetings learned PHP(eople), There have been a number of postings recently on opening and reading files, and whilst I have read `em all I fail to make sense of it all. Basicaly...I have a text file with entries in it...I wish to display the contents of this file line by line in an HTML table : At present all I get is a table with 1 row and all the text in it in a large messy blob. = html body ?php $handle = fopen(fopen.txt,r); echo 'table border=1'.\n; echo ' tr'.\n; echo ' td width=15%bFile Entries/b/td'.\n; echo ' /tr'.\n.\n; // //For each line in the file // while (fpassthru($handle)); //{ //Print them out to Table- echo 'tr'.\n; echo ' td width=15%font size=2'; echo fpassthru($handle); echo '/td/tr'. \n; //} echo '/table'; //fclose($handle); ? /body /html = I have commented out those lines which fail and am stuck as to what the correct syntax should be. I have read up on nl2br,fgets and other posts on php.net, but ..harump Thanks -- Chris Blake Office : (011) 782-0840 Cell : 083 985 0379 It is reported that somewhere in the world, every 15 seconds, a woman gives birth to a child. She must be found and stopped. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ### This message has been scanned by F-Secure Anti-Virus for Internet Mail. For more information, connect to http://www.F-Secure.com/ ### This message has been scanned by F-Secure Anti-Virus for Internet Mail. For more information, connect to http://www.F-Secure.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Chris Blake Office : (011) 782-0840 Cell : 083 985 0379 It is reported that somewhere in the world, every 15 seconds, a woman gives birth to a child. She must be found and stopped. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] text file reading and overwrite
Have a problem in reading a text file and displaying it in a text box area,also what function should i used to overwrite an existing text file. For textarea type text boxes, use the following - textarea$var/textarea Please note that if you include *any* kind of spaces or tabs or other characters between the textarea tags that it will dump them into the text area as well. i.e. - textarea $var /textarea The 'action' file of the form will receive the following (unless the contents are modified of course) - \n$var\n For input type text boxes, use the following - input type='text' value='$var' / As to reading a file, see Example 1 under fgets(). For deleting files, see unlink(). Patrick p.s. you'll want to html encode $var before dumping it into either one of these or else the contents of $var could mess up the html in the page. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] text file reading and overwrite
I can't tell you anything about your problem without knowing what's going on (error messages are helpful). As for overwriting a file, just use: fopen($filename,w); The w option tells it to open the file for writing and to truncate it to zero-length. ---Matt, XPODesigns.com -Original Message- From: Michael P. Carel [mailto:[EMAIL PROTECTED] Sent: Monday, February 24, 2003 7:04 PM To: [EMAIL PROTECTED] Subject: [PHP] text file reading and overwrite Hi, Have a problem in reading a text file and displaying it in a text box area,also what function should i used to overwrite an existing text file. mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Text file
... so open up the text file and read it. What problem are you having? Are permissions set correctly? Are you making sure to escape \ on Win? --- Scott Hurring Systems Programmer EAC Corporation [EMAIL PROTECTED] Voice: 201-462-2149 Fax: 201-288-1515 -Original Message- From: Rodrigo [mailto:[EMAIL PROTECTED]] Sent: Monday, May 20, 2002 4:57 PM To: [EMAIL PROTECTED] Subject: [PHP] Text file Hi guys: What I need is a php file that will read a text file and show it on a html file. And it will also write to a text file, but at the end of the file. Thanx, Rodrigo de Oliveira Costa. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Text file
On Mon, 20 May 2002, Rodrigo wrote: What I need is a php file that will read a text file and show it on a html file. And it will also write to a text file, but at the end of the file. Well, you're in luck; that's all very easy to do. Are you having a specific problem with some aspect of it? A good starting point is the PHP manual page for fopen(). miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Text File Formating.
the manual is your friend. http://www.php.net/manual/en/function.nl2br.php * * Cal Evans * Journeyman Programmer * Techno-Mage * http://www.calevans.com * -Original Message- From: Randum Ian [mailto:[EMAIL PROTECTED]] Sent: Monday, April 29, 2002 10:20 AM To: PHP Subject: [PHP] Text File Formating. Hi there, I have got various text files which I need to convert on the fly to HTML with PHP. How do I convert this: --- TEXT --- CHART RETURN Chart Date: blah No. Artist - 'Track (Remix)' (Label) 1. blah - 'blah (blah mix)' (blah) --- END TEXT--- to this: --- HTML --- CHART RETURNbr / br / Chart Date: blahbr / br / No. Artist - 'Track (Remix)' (Label)br / br / 1. blah - 'blah (blah mix)' (blah)br / --- END TEXT--- Any help much appreciated, Ian. --- Randum Ian DJ / Reviewer / Webmaster, DancePortal (UK) Limited [EMAIL PROTECTED] http://www.danceportal.co.uk DancePortal.co.uk - Global dance music media -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: php, text file, and mysql
If you are not going to save, I wouldn't call it a file :-) Just store the contents in a string and insert in a TEXT (etc) field. -- Julio Nobrega. Um dia eu chego lá: http://sourceforge.net/projects/toca Ajudei? Salvei? Que tal um presentinho? http://www.submarino.com.br/wishlistclient.asp?wlid=664176742884 Gregory Hernandez [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... hello everyone. i'm wondering if i can do the following: FIRST, using php, can i create/generate a text file on-the-fly (not saved to a server) THEN, insert the actual text file (and not its contents) into a mysql database. many thanks in advance, gregory hernandez [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php