[consulting] Editing a .txt file with script

Christopher M. Jones cjones at partialflow.com
Fri Oct 22 21:02:03 UTC 2010


Couple of things:

1. This is a support question, unless you're looking to hire someone to 
do it for you.

2. It's a php question, not a Drupal one.

You need to read up on the string handling functions in PHP. 
Particularly, you want to look at preg_replace() and friends. And you're 
about to have lots of fun with regexp ;-) When you get to that point, 
Google is your friend. Your task is a common one.

On 10/22/2010 03:52 PM, Holly Ferree wrote:
> Hello All,
>
> I have figured out how to open a text file and erase and add new
> content... I also know how to add content at the end of the file....
>
> How do I do search and replace?
>
> This is the default look for the line of code:
>
>        1167-67271: 10/18  6:45p 186MB 111Pts v8.55.4/9.0.2.3642
> Tipsword, Georgia         SUCCESS
>
> This is how I was told to format it (a little more complex than before):
>
> 1167, 67271, 10/18/2010(CONVERT TO DATE FORMAT), 6:45p(CONVERT TO TIME
> FORMAT 18:45), 186000000, 111, v8.55.4, 9.0.2, 3642, Tipsword, Georgia,
> SUCCESS
>
> This is the code that I have so far:
>
> <?php
> $myFile = "test.txt";
> $fh = fopen($myFile, 'r+') or die("can't open file");
>
> WHAT CAN I PUT HERE TO REPLACE ALL THE SPACES AND THEN ADD A COMMA WEAR
> NEEDED?
>
> fclose($fh);
>
>
> --------------------
> It needs to be a script because it has hundreds of lines and the report
> comes in once a day. Any ideas?
>
> Any help is appreciated,
>
> Holly Ferree
>
> (one person I asked suggested using visual basic instead of php by
> creating a .vbs or .vba script using Regular Expressions (Regex) (mix of
> find and replace strings like \s+ .... any help on what experssions to
> use would be great) and then using an action in outlook 2007 to run the
> script when the subject name of Connect Report with the connect.txt
> attached is recieved)
>
>
>
> _______________________________________________
> consulting mailing list
> consulting at drupal.org
> http://lists.drupal.org/mailman/listinfo/consulting


More information about the consulting mailing list