Re: Writing double-prime to file? [message #184782 is a reply to message #184781] |
Sat, 01 February 2014 15:11 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 2/1/2014 9:23 AM, Adrian Tuddenham wrote:
> Jerry Stuckle <jstucklex(at)attglobal(dot)net> wrote:
>
>> On 2/1/2014 6:37 AM, Adrian Tuddenham wrote:
>>> I am trying to write a series of programs which create a file from a
>>> string which has been Copied from a spreadsheet. It is Pasted into an
>>> HTML Form and passed through various checking routines. Finally it is
>>> written to a file.
>>>
>>> If the string contains a double-prime character (double quotes) the
>>> character and the rest of the string after that point do not appear to
>>> be written to file.
>>>
>>> The program displays the string just after the "write to file" lines
>>> and it is still unchanged. Either a problem is occurring during the
>>> writing phase or that character is making the rest of the file
>>> unreadable. (I view the file contents in Fetch v3.0.3)
>>>
>>> The data string is held in the variiable '$txt' and the write command
>>> is:
>>>
>>> ~~~~~~~~
>>> $fh = fopen($fileURL, 'w') or die("<FONT
>>> COLOR=\"#CCFFFF\"><B>PayFileGen2 can't open file $fileURL</B></FONT>");
>>> fwrite($fh, $txt);
>>> fclose($fh);
>>>
>>> ~~~~~~~~
>>>
>>> Is that character known to cause a problem and is there a
>>> straightforward way around this?
>>>
>>>
>>
>> I've never seen a problem writing double quotes to a file. What does
>> the file look like if you open it with an editor on the server (or, more
>> simply, just list it to the terminal) instead of retrieving it with an
>> ftp program?
>
> I am just a beginner, so 'listing to the termiinal' is something I
> haven't come across. I didn't FTP the file to view it, but used the
> "View file" facility in Fetch (I don't know if that would make any
> difference to what I would see). If you want to see it, the file is at:
> http://www.poppyrecords.co.uk/Payment/phpfiles/IYC519N1391274673.txt
>
> I have written a bit of code to read the file, print it and then and
> list each character with its ASCII equivlent. The original data was:
>
> ~~~~~~~~~ Original Data ~~~~~~
> 419 IYC519 140201 169.75 XXX111
> Bill Smith 123, Any Street Some Town Elsewhere County
> XX1 @AB 01234 567890 bill(dot)smith(at)url(dot)com
> 0 Copy tape (0.25" @ 1-7/8ips) to CDR 0
> Special treatment 0 Hours work 4
> 15 60 P+P 1 3 3 Transfer 8 double-sided
> discs to CDR 0 Hours work 6.5 15
> 97.5 P+P CDR 1 1 1 P+P Special Delivery 1
> 8.25 8.25 0
>
> ~~~~~~~ End of original data ~~~~~~
>
>
> The results from the reading program are:
>
> ~~~~~~~~ Reading program results ~~~~~~
> 419 IYC519 140201 169.75 XXX111
> Bill Smith 123, Any Street Some Town Elsewhere County
> XX1 @AB 01234 567890 bill(dot)smith(at)url(dot)com
> 0 Copy tape (0.25
>
> 0 4 = 52
> 1 1 = 49
> 2 9 = 57
> 3 = 9
> 4 I = 73
> 5 Y = 89
> 6 C = 67
> 7 5 = 53
> 8 1 = 49
> 9 9 = 57
> 10 = 9
> 11 1 = 49
> 12 4 = 52
> 13 0 = 48
> 14 2 = 50
> 15 0 = 48
> 16 1 = 49
> 17 = 9
> 18 = 9
> 19 = 9
> 20 = 9
> 21 1 = 49
> 22 6 = 54
> 23 9 = 57
> 24 . = 46
> 25 7 = 55
> 26 5 = 53
> 27 = 9
> 28 = 9
> 29 X = 88
> 30 X = 88
> 31 X = 88
> 32 1 = 49
> 33 1 = 49
> 34 1 = 49
> 35 = 9
> 36 B = 66
> 37 i = 105
> 38 l = 108
> 39 l = 108
> 40 = 9
> 41 S = 83
> 42 m = 109
> 43 i = 105
> 44 t = 116
> 45 h = 104
> 46 = 9
> 47 1 = 49
> 48 2 = 50
> 49 3 = 51
> 50 , = 44
> 51 = 32
> 52 A = 65
> 53 n = 110
> 54 y = 121
> 55 = 32
> 56 S = 83
> 57 t = 116
> 58 r = 114
> 59 e = 101
> 60 e = 101
> 61 t = 116
> 62 = 9
> 63 S = 83
> 64 o = 111
> 65 m = 109
> 66 e = 101
> 67 = 32
> 68 T = 84
> 69 o = 111
> 70 w = 119
> 71 n = 110
> 72 = 9
> 73 E = 69
> 74 l = 108
> 75 s = 115
> 76 e = 101
> 77 w = 119
> 78 h = 104
> 79 e = 101
> 80 r = 114
> 81 e = 101
> 82 = 9
> 83 C = 67
> 84 o = 111
> 85 u = 117
> 86 n = 110
> 87 t = 116
> 88 y = 121
> 89 = 9
> 90 X = 88
> 91 X = 88
> 92 1 = 49
> 93 = 32
> 94 @ = 64
> 95 A = 65
> 96 B = 66
> 97 = 9
> 98 0 = 48
> 99 1 = 49
> 100 2 = 50
> 101 3 = 51
> 102 4 = 52
> 103 = 32
> 104 5 = 53
> 105 6 = 54
> 106 7 = 55
> 107 8 = 56
> 108 9 = 57
> 109 0 = 48
> 110 = 9
> 111 b = 98
> 112 i = 105
> 113 l = 108
> 114 l = 108
> 115 . = 46
> 116 s = 115
> 117 m = 109
> 118 i = 105
> 119 t = 116
> 120 h = 104
> 121 @ = 64
> 122 u = 117
> 123 r = 114
> 124 l = 108
> 125 . = 46
> 126 c = 99
> 127 o = 111
> 128 m = 109
> 129 = 9
> 130 = 9
> 131 = 9
> 132 = 9
> 133 0 = 48
> 134 = 9
> 135 C = 67
> 136 o = 111
> 137 p = 112
> 138 y = 121
> 139 = 32
> 140 t = 116
> 141 a = 97
> 142 p = 112
> 143 e = 101
> 144 = 32
> 145 ( = 40
> 146 0 = 48
> 147 . = 46
> 148 2 = 50
> 149 5 = 53
> 150 = 0
> 151 = 0
> 152 = 0
> 153 = 0
> 154 = 0
> 155 = 0
> 156 = 0
> 157 = 0
> 158 = 0
> 159 = 0
> 160 = 0
> 161 = 0
> 162 = 0
> 163 = 0
> 164 = 0
> 165 = 0
> 166 = 0
> 167 = 0
> 168 = 0
> 169 = 0
> 170 = 0
> 171 = 0
> 172 = 0
> 173 = 0
> 174 = 0
> 175 = 0
> 176 = 0
> 177 = 0
> 178 = 0
> 179 = 0
> 180 = 0
> 181 = 0
> 182 = 0
> 183 = 0
> 184 = 0
> 185 = 0
> 186 = 0
> 187 = 0
> 188 = 0
> 189 = 0
> 190 = 0
> 191 = 0
> 192 = 0
> 193 = 0
> 194 = 0
> 195 = 0
> 196 = 0
> 197 = 0
> 198 = 0
> 199 = 0
>
> ~~~~~~~ end of reading program results ~~~~~~~~
>
>
> The reading program was:
>
> ~~~~~~~ Reading program ~~~~~~~~~
> <?php
>
>
> ## GET file URL from link and read data from file ###
>
> $fileURL = $_GET['iyc'];
>
> $fileURL = ($_SERVER['DOCUMENT_ROOT'] . "/Payment/phpfiles/") .
> $fileURL;
> $fh = fopen($fileURL, 'r') or die("<FONT COLOR=\"#CCFFFF\"><B>invoicer3
> can't open file $fileURL</B></FONT>");
> $txt = fread($fh, filesize($fileURL));
> fclose($fh);
>
> print $txt;
> print "
>
> ";
>
> $i=0;
>
> while ($i<200)
> {
> print $i . " ";
> print ($txt{$i}) . " = ";
> print (ord($txt{$i}));
> print "
> ";
> $i++;
> }
>
>
> ?>
>
> ~~~~~ end of reading program ~~~~~
>
>
>
Well, first of all, if you're going to do any web work, you need a local
development system to test on. This means duplicating as close as you
can the same software you have on your production system (NEVER do
development on a production system!).
And right now you have a number of different programs involved, any of
which can be causing a problem, even how you're handling the cut/paste
in your code.
fwrite() doesn't have a problem with writing double quotes to a file;
such a problem would render it pretty useless.
Listing the file to the terminal means display its contents on the local
terminal. Windows users would use the 'type' command; in *nix systems
the command is 'cat'. But you need to be at a command prompt on the
system with the file to use it (something you also need to be able to do).
What is in $txt immediately after the fwrite()?
BTW - you should NEVER use die() in production code. It terminates
processing of EVERYTHING (including the HTML) immediately, resulting in
invalid HTML being sent to the browser. Rather, you should test for
failure, and if it fails, just not execute the code dependent on the
operation working (and put out a failure message instead, if you wish).
You also realize your code is not multiprocessing safe. What happens,
for instance, if two people try to write to the same file at the same
time? Or after one person writes, a second one overwrites the file with
different data? There is no guarantee a filename passed in a URL is unique.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
|
|
|