Jump to content

mikebyrne

Members
  • Posts

    780
  • Joined

  • Last visited

Posts posted by mikebyrne

  1. I've changed it to

    <?php
    $rewrote = "";
    $handle = fopen("C:\Users\Mike\Desktop\AthyDB.txt", "r+"); // Open file to read it read.
    
    if ($handle) {
    while (!feof($handle)) // Loop til end of file.
    {
    $currentline = fgets($handle, 4096); // Read a line.
    $currentline=preg_replace('/^D/','Dail European Parliament and Local Elections only', $currentline);
    $currentline=preg_replace('/^S/','Post or special arrangement only', $currentline);
    $currentline=preg_replace('/^L/','Local Elections only', $currentline);
    $currentline=preg_replace('/^E/','European Parliament and Local Elections only', $currentline);
    $rewrote .= $currentline;
    $rewrote .= "\n";
    }
    file_put_contents('C:\Users\Mike\Desktop\test.txt', $rewrote);
    fclose($handle);
    }
    ?>
    

     

    And it is now working! Thanks for all the help!!

  2. Sorry! Good spot

     

    Im now getting the error

     

    Warning: preg_replace() [function.preg-replace]: No ending delimiter '^' found in C:\xampp\htdocs\letters.php on line 9

     

    Warning: preg_replace() [function.preg-replace]: No ending delimiter '^' found in C:\xampp\htdocs\letters.php on line 10

     

    Warning: preg_replace() [function.preg-replace]: No ending delimiter '^' found in C:\xampp\htdocs\letters.php on line 11

     

    Warning: preg_replace() [function.preg-replace]: No ending delimiter '^' found in C:\xampp\htdocs\letters.php on line 12

     

    Should the code  be '^S,' or something??  (No I just tried it!)

  3. with ths code

     

    <?php
    $rewrote = "";
    $handle = fopen("C:\Users\Mike\Desktop\AthyDB.txt", "r+"); // Open file to read it read.
    
    if ($handle) {
    while (!feof($handle)) // Loop til end of file.
    {
    $currentline = fgets($handle, 4096); // Read a line.
    $currentline=preg_replace('^D','Dail European Parliament and Local Elections only', $currentline);
    $currentline=preg_replace('^S','Post or special arrangement only', $currentline));
    $currentline=preg_replace('^L','Local Elections only', $currentline));
    $currentline=preg_replace('^E','European Parliament and Local Elections only', $currentline));
    $rewrote .= $currentline;
    $rewrote .= "\n";
    }
    file_put_contents('C:\Users\Mike\Desktop\test.txt');
    fclose($handle);
    }
    ?>
    

     

    Im getting a parse error "Parse error: parse error in C:\xampp\htdocs\letters.php on line 10"

     

    Line 10 is $currentline=preg_replace('^S','Post or special arrangement only', $currentline));

     

  4. I've tried with the following code

     

    <?php
    $fields=file('C:\Users\Mike\Desktop\AthyDB.txt');
        foreach($fields as $i=>$field)
        {
    	$field=preg_replace('^D','Dail European Parliament and Local Elections only');
    	$field=preg_replace('^S','Post or special arrangement only');
    	$field=preg_replace('^L','Local Elections only');
    	$field=preg_replace('^E','European Parliament and Local Elections only');
           $fields[$i]=$field;
        }
        file_put_contents('C:\Users\Mike\Desktop\test.txt',implode("\r",$fields));
    ?>
    

     

     

     

     

    but im getting the following error

     

     

    Warning: Wrong parameter count for preg_replace() in C:\xampp\htdocs\replace.php on line 5

     

    Warning: Wrong parameter count for preg_replace() in C:\xampp\htdocs\replace.php on line 6

     

    Warning: Wrong parameter count for preg_replace() in C:\xampp\htdocs\replace.php on line 7

     

    Warning: Wrong parameter count for preg_replace() in C:\xampp\htdocs\replace.php on line 8

  5. I have a file that looks something like the following:

     

    D,2796,Son,Oler,13 Dun Bnn,Bch Road,Ahy,Co.Kire

    S,2797,Gerty,Laurce,15  Dun Brn,Bleach ad,Ahy,Co.Kilde

    L,2801,Mazse,Saras,17  Dn Brn,Blch Rod,Aty,Co.Kilre

    E,2808,Esjo,Leel,21  Dun Bnn,Blach Road,Ay,Co.Kilre

     

    What I am trying to do is replace the single character letters "D","S","L" & "E" with the following sentences

     

    Dail European Parliament and Local Elections only  (instead of D)

     

    European Parliament and Local Elections only (instead of E)

     

    Local Elections only (instead of L)

     

    Post or special arrangement only (instead of S)

     

    Is it possible to code this instead of manually replacing them??

     

    Ideally I would like the output to pass into a new file

  6. Im looking to write a piece of code that will remove all the double spacing in my comma separated file and have it as a single space.

     

    My file looks like this:

     

    ,1517,Phxxxips,Txxxxxsa,,4  Gallxxxxshill,Axxxxy,Co.Kxxxxxare

    ,1517,Phxxxips,Txxxxxsa,,4  Gallxxxxshill,Axxxxy,Co.Kxxxxxare

    ,1517,Phxxxips,Txxxxxsa,,4  Gallxxxxshill,Axxxxy,Co.Kxxxxxare

     

    I would like my output to look like:

     

    ,1517,Phxxxips,Txxxxxsa,,4 Gallxxxxshill,Axxxxy,Co.Kxxxxxare

     

    Any help would be great!

  7. Im trying to insert a csv file into my database but im getting the error

     

    "Invalid parameter for CSV import: Fields escaped by"

     

    A line on my file looks like this:

     

    ,6778,Bxxxn,Anxxe,,76 Whxxxxecxxastle Lawn,Axxxy,Co.Kxxxare,
    

     

    What should I place in the following??

     

    Fields terminated by

    Fields enclosed by

    Fields escaped by

    Lines terminated by

  8. I've got the code working but the out put looks like:

     

    ,2947,Bxxxy,Bxxry,20 Dun Brxxxnn,Sunxxxide Lawns Axxy Co.Kilxxxxre

     

    ,2948,Bxxxy,Isxxxl,20 Dun Brxxxn,Sunxxxide Lawns Axxy Co.Kilxxxxe

     

    It doesnt seem to put the commas near the end ie

     

    ,2948,Bxxxy,Isxxxl,20 Dun Brxxxn,Sunxxxide Lawns, Axxy, Co.Kilxxxxe

     

    Is it because Axxy Co.Kilxxxxe are single spaced??

  9. I now have the following code but getting the error

     

    Warning: implode() [function.implode]: Argument must be an array in C:\xampp\htdocs\commainsert.php on line 9

     

    My code is:

     

    <?php
    $fields=file('C:\Users\Mike\Desktop\5april.txt');
        foreach($fields as $i=>$field)
        {
           $field=str_replace('  ',',',$field);
           $field=str_replace(', ',',',$field);
           $fields[$i]=$field;
        }
        file_put_contents('C:\Users\Mike\Desktop\test.txt',implode("\r\n",$array_containing_lines));
    ?>
    

     

  10. Would there be a way of inputing the file instead of typing the below? (sometihng like $fields[] = 'C:\desktop\filename.txt')

     

        $fields[]='  2981  Rxxxe, Vixxxnt  1  Flixxxxs Clxxxe Axxxy Co.Kildare';

        $fields[]='  2982  Bxxxxe, Anxxxxe  2  Flxxxrs Cxxxxe Axxxy Co.Kildare';

        $fields[]='L  2983  Vxxxie, Alxxxxra  4  Flixxxxs Cxxxxe Axxxxy Co.Kildare';

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.