-
Posts
780 -
Joined
-
Last visited
Posts posted by mikebyrne
-
-
That seems to have fixed that issue but im now getting the error
Warning: file_put_contents() expects at least 2 parameters, 1 given in C:\xampp\htdocs\letters.php on line 16
Line 16 is
file_put_contents('C:\Users\Mike\Desktop\test.txt');
-
Sorry, what do you mean by changing them to include /'s??
-
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!)
-
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));
-
No problem Blueman378 it was just frustrating me
I'll try the code out in a bit, I'm just away from the other pc
-
Thanks, very useful
I've tried that and it seemed to lean towards an older version of php being the issue but im all up to date
-
Cant see where I'm going wrong with this??
-
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
-
No, as stated in my last post Im just asking for advice on which option to go with the preg replace or by using the switch
-
Anymore help on this matter would be great
-
Im a little confused as to which one to try?
Also how do I code so it takes in the file and outputs to another?
ps thanks for the help so far!
-
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
-
Thanks for the help!
How would I send the output to a file rather than on displaying it on screen?
-
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!
-
I leave the rest blank but still get the "Fields escaped by" error
-
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
-
Problem solved! Thanks for all the help
-
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??
-
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)); ?>
-
Yeah the file only contains about 3,000 lines if that. How do I send the output to a file instead of displaying it in a browser?
-
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';
-
thanks for the help guys!
-
So if i was to remove the comma how can i code the php to put the comma in the double spaces?
-
Any help on this would be great
[SOLVED] Replacing single letters with sentence?
in PHP Coding Help
Posted
I've changed it to
And it is now working! Thanks for all the help!!