Re: [PHP] magical file writing truncation
> > [snip] > > $newFile = "xml/".$type."/".$now.".xml"; > > while(file_exists($newFile)) > >$newFile = "xml/".$type."/".$now++.".xml"; > > $text = $_POST['text']; > > $text = urlencode(stripslashes(nl2br($text))); > > [/snip] > > ack, sorry to double post... it appears that it actually reverse truncates the $text... so it cuts off the beginning of the text, and leaves the end bit. i can understand this happening as an XML interpreter as the tags get in the way, but these are urlencoded, and writing to the file has nothing to do with the XML functions. i dunno if this is maybe a bug in PHP? i can't get my head round why it looses have my string in 2 lines... thanks again for the help... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] magical file writing truncation
Let's work backwards then. Instead of $text = urlencode(stripslashes(nl2br($text))); try $text = urlencode(nl2br($text)); echo "$text"; Can you post the first couple of raw lines of text and then the echo'd output? -- okay, the first few lines of raw text are as follows... it's a chat log btw... Session Start (Yahoo! - fatcubanskate:the_lady_in_waiting1982): Thu Jul 10 21:23:42 2003 [21:23] the_lady_in_waiting1982: hey sexy!!! [21:24] fatcubanskate: hey sugar [21:24] fatcubanskate: how\'s thing? [21:25] the_lady_in_waiting1982: you know we could do a whole roll playing thing, that would be a big as turn on [21:25] fatcubanskate: oh really? like... i pretend to be a pirate? [21:25] fatcubanskate: raaar!!! and then the first few lines of the echo'd output... Session+Start+%28Yahoo%21+-+fatcubanskate%3Athe_lady_in_waiting1982%29%3A+Th u+Jul+10+21%3A23%3A42+2003+%3Cbr+%2F%3E%0D%0A%5B21%3A23%5D+the_lady_in_waiti ng1982%3A+hey+sexy%21%21%21+%3Cbr+%2F%3E%0D%0A%5B21%3A24%5D+fatcubanskate%3A +hey+sugar+%3Cbr+%2F%3E%0D%0A%5B21%3A24%5D+fatcubanskate%3A+how%5C%27s+thing %3F+%3Cbr+%2F%3E%0D%0A%5B21%3A25%5D+the_lady_in_waiting1982%3A+you+know+we+c ould+do+a+whole+roll+playing+thing%2C+that+would+be+a+big+as+turn+on+%3Cbr+% 2F%3E%0D%0A%5B21%3A25%5D+fatcubanskate%3A+oh+really%3F+like...+i+pretend+to+ be+a+pirate%3F+%3Cbr+%2F%3E%0D%0A%5B21%3A25%5D+fatcubanskate%3A+raaar%21%21% 21 seems about right? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] magical file writing truncation
[snip] > > [snip] > > $newFile = "xml/".$type."/".$now.".xml"; > > while(file_exists($newFile)) > >$newFile = "xml/".$type."/".$now++.".xml"; > > $text = $_POST['text']; > > $text = urlencode(stripslashes(nl2br($text))); > > [/snip] > > ack, sorry to double post... it appears that it actually reverse truncates the $text... so it cuts off the beginning of the text, and leaves the end bit. i can understand this happening as an XML interpreter as the tags get in the way, but these are urlencoded, and writing to the file has nothing to do with the XML functions. [/snip] Let's work backwards then. Instead of $text = urlencode(stripslashes(nl2br($text))); try $text = urlencode(nl2br($text)); echo "$text"; Can you post the first couple of raw lines of text and then the echo'd output? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] magical file writing truncation
[snip] i really can't get my head around this one at all. could it possibly be a windows issue??? i know windows can be an arse in dealing with files, but i can't see how it could pick up on a variable inside PHP and truncate it? [/snip] I just have one more thought because you brought up Windows. Change the name of the variable "$text" . text might just be one of those reserved or key words - nope, same deal... ah well, thanks again :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] magical file writing truncation
[snip] $newFile = "xml/".$type."/".$now.".xml"; while(file_exists($newFile)) $newFile = "xml/".$type."/".$now++.".xml"; $text = $_POST['text']; $text = urlencode(stripslashes(nl2br($text))); [/snip] At this point (for testing putposes) I would echo "$text"; and start looking for clues. If I were a betting man I would have to say that there is some problem with quotes within the text. I hope that this points you in the right direction. Have a pleasant and fruitful day! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] magical file writing truncation
I didn't see anything right off of the bat. You may want to output the text both ways and then compare them using http://us3.php.net/manual/en/function.strcmp.php apart from the fact that the slashes are there in one, and not in the other, there is no difference... $fp = fopen($newFile, "wb"); $bytes = fwrite( $fp, $text ); print $bytes." written"; fclose( $fp ); ... tells me that 5287 bytes were written, and my file shows the full text... $fp = fopen($newFile, "wb"); $bytes = fwrite( $fp, $newContent ); print " - ".$bytes." written"; fclose( $fp ); ... tells me that 5520 bytes were written, but opening the file shows that half the text is missing... the number of bytes wrtten seems to be correct. if i run a strlen() against each string, then i get the same length as bytes, so that sounds about right... but the files just aren't right. everything would point to the fact that everything is happening correctly... but it just isn't... i really can't get my head around this one at all. could it possibly be a windows issue??? i know windows can be an arse in dealing with files, but i can't see how it could pick up on a variable inside PHP and truncate it? obviously there's no simple solution here... can anyone point me in the way of an alternative way of doing this? i could try the file write in 3 stages, first part of content, text, end of content, as they seem to write fine seperatly. arse... thanks loads for your help so far tho jay... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] magical file writing truncation
[snip] OK, put stripslashes back in and show the echo'd out put again. - $text = urlencode(stripslashes(nl2br($text))); print $text; [/snip] I didn't see anything right off of the bat. You may want to output the text both ways and then compare them using http://us3.php.net/manual/en/function.strcmp.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] magical file writing truncation
[snip] Session+Start+%28Yahoo%21+-+fatcubanskate%3Athe_lady_in_waiting1982%29%3 A+Th u+Jul+10+21%3A23%3A42+2003+%3Cbr+%2F%3E%0D%0A%5B21%3A23%5D+the_lady_in_w aiti ng1982%3A+hey+sexy%21%21%21+%3Cbr+%2F%3E%0D%0A%5B21%3A24%5D+fatcubanskat e%3A +hey+sugar+%3Cbr+%2F%3E%0D%0A%5B21%3A24%5D+fatcubanskate%3A+how%5C%27s+t hing %3F+%3Cbr+%2F%3E%0D%0A%5B21%3A25%5D+the_lady_in_waiting1982%3A+you+know+ we+c ould+do+a+whole+roll+playing+thing%2C+that+would+be+a+big+as+turn+on+%3C br+% 2F%3E%0D%0A%5B21%3A25%5D+fatcubanskate%3A+oh+really%3F+like...+i+pretend +to+ be+a+pirate%3F+%3Cbr+%2F%3E%0D%0A%5B21%3A25%5D+fatcubanskate%3A+raaar%21 %21% 21 [/snip] OK, put stripslashes back in and show the echo'd out put again. - $text = urlencode(stripslashes(nl2br($text))); print $text; .. Session+Start+%28Yahoo%21+-+fatcubanskate%3Athe_lady_in_waiting1982%29%3A+Th u+Jul+10+21%3A23%3A42+2003+%3Cbr+%2F%3E%0D%0A%5B21%3A23%5D+the_lady_in_waiti ng1982%3A+hey+sexy%21%21%21+%3Cbr+%2F%3E%0D%0A%5B21%3A24%5D+fatcubanskate%3A +hey+sugar+%3Cbr+%2F%3E%0D%0A%5B21%3A24%5D+fatcubanskate%3A+how%27s+thing%3F +%3Cbr+%2F%3E%0D%0A%5B21%3A25%5D+the_lady_in_waiting1982%3A+you+know+we+coul d+do+a+whole+roll+playing+thing%2C+that+would+be+a+big+as+turn+on+%3Cbr+%2F% 3E%0D%0A%5B21%3A25%5D+fatcubanskate%3A+oh+really%3F+like...+i+pretend+to+be+ a+pirate%3F+%3Cbr+%2F%3E%0D%0A%5B21%3A25%5D+fatcubanskate%3A+raaar%21%21%21 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] magical file writing truncation
[snip] okay, the first few lines of raw text are as follows... it's a chat log btw... Session Start (Yahoo! - fatcubanskate:the_lady_in_waiting1982): Thu Jul 10 21:23:42 2003 [21:23] the_lady_in_waiting1982: hey sexy!!! [21:24] fatcubanskate: hey sugar [21:24] fatcubanskate: how\'s thing? [21:25] the_lady_in_waiting1982: you know we could do a whole roll playing thing, that would be a big as turn on [21:25] fatcubanskate: oh really? like... i pretend to be a pirate? [21:25] fatcubanskate: raaar!!! and then the first few lines of the echo'd output... Session+Start+%28Yahoo%21+-+fatcubanskate%3Athe_lady_in_waiting1982%29%3 A+Th u+Jul+10+21%3A23%3A42+2003+%3Cbr+%2F%3E%0D%0A%5B21%3A23%5D+the_lady_in_w aiti ng1982%3A+hey+sexy%21%21%21+%3Cbr+%2F%3E%0D%0A%5B21%3A24%5D+fatcubanskat e%3A +hey+sugar+%3Cbr+%2F%3E%0D%0A%5B21%3A24%5D+fatcubanskate%3A+how%5C%27s+t hing %3F+%3Cbr+%2F%3E%0D%0A%5B21%3A25%5D+the_lady_in_waiting1982%3A+you+know+ we+c ould+do+a+whole+roll+playing+thing%2C+that+would+be+a+big+as+turn+on+%3C br+% 2F%3E%0D%0A%5B21%3A25%5D+fatcubanskate%3A+oh+really%3F+like...+i+pretend +to+ be+a+pirate%3F+%3Cbr+%2F%3E%0D%0A%5B21%3A25%5D+fatcubanskate%3A+raaar%21 %21% 21 [/snip] OK, put stripslashes back in and show the echo'd out put again. -- 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] magical file writing truncation
[snip] i really can't get my head around this one at all. could it possibly be a windows issue??? i know windows can be an arse in dealing with files, but i can't see how it could pick up on a variable inside PHP and truncate it? [/snip] I just have one more thought because you brought up Windows. Change the name of the variable "$text" . text might just be one of those reserved or key words -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] magical file writing truncation
> > obviously there's no simple solution here... can anyone point me in the way > of an alternative way of doing this? i could try the file write in 3 stages, > first part of content, text, end of content, as they seem to write fine > seperatly. > this is magical, evening seperating the file open, and file write into 3 stages, it still looses half my $text, but again, if i write $text to it's own file, then it's perfectly fine, and all contents go inside... i have this... print "start: ".strlen($newStartContent).""; print "text: ".strlen($text).""; print "end: ".strlen($newEndContent).""; touch($newFile); $fp = fopen($newFile, "ab"); $bytes = fwrite( $fp, $newStartContent ); $totalBytes += $bytes; print " - ".$bytes." written"; fclose( $fp ); unset( $fp ); $fp = fopen($newFile.".txt", "at"); $bytes = fwrite( $fp, $text ); $totalBytes += $bytes; print " - ".$bytes." written"; fclose( $fp ); unset( $fp ); $fp = fopen($newFile, "ab"); $bytes = fwrite( $fp, $newEndContent ); $totalBytes += $bytes; print " - ".$bytes." written"; fclose( $fp ); unset( $fp ); print "Total size written ".$totalBytes; i figured i would totally kill $fp each time with an unset just incase. in the above example the $text is being saved to a different file, and the write is fine. take the ".txt" off so it saves to the same file, and it cuts off half the $text again. truly magical... i'm gonna have to rethink this whole thing aren't i? ah well... thanks again for the help... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] magical file writing truncation
> [snip] > $newFile = "xml/".$type."/".$now.".xml"; > while(file_exists($newFile)) >$newFile = "xml/".$type."/".$now++.".xml"; > $text = $_POST['text']; > $text = urlencode(stripslashes(nl2br($text))); > [/snip] > > At this point (for testing putposes) I would echo "$text"; and start > looking for clues. If I were a betting man I would have to say that > there is some problem with quotes within the text. I hope that this > points you in the right direction. been doing some more testing. $text seems to stay intact throughout, it is exactly what it should be. if i do an fwrite( $fp, $text ) then it writes perfectly all contents of the $text as i would expect. i shouldn't get any problems with quotes or other characters as the whole lot is urlencode()'d > Have a pleasant and fruitful day! wow, everyone on this list should be THAT cheery :) thanks mate, you too! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php