mtorbin Posted May 11, 2009 Share Posted May 11, 2009 Hey all, I have an odd issue that I've never quite seen before and I'm wondering if it has something to do with the way that fwrite is working (possibly coupled with issues in my data). Without a lengthy explanation of extraneous details, I have an array with each item in the array having something like the following (spacing was intentional): $myArray[1] = " <xmlTag>[DATA]</xmlTag> <newTag>[DATA]</newTag> <thirdTag>[DATA]</thirdTag>"; However, when it gets written to the file, I have this (again, spacing is intentional): <xmlTag>[DATA]</xmlTag> <newTag>[DATA]</newTag> <thirdTag>[DATA]</thirdTag> (note the double carriage returns) I've run print outputs all throughout the script to test what's going on and I'm viewing the responses in Terminal (on Mac). All of the print outputs display correctly. The only thing that displays incorrectly is the final data written in the text file. Has anyone else seen this before? Thanks, - MT Quote Link to comment https://forums.phpfreaks.com/topic/157709-whats-really-going-on-with-fwrite/ Share on other sites More sharing options...
Mchl Posted May 11, 2009 Share Posted May 11, 2009 Check the byte values for these new line characters. (Open the file in an editor that lets you view contents in hexadecimal.) Quote Link to comment https://forums.phpfreaks.com/topic/157709-whats-really-going-on-with-fwrite/#findComment-831800 Share on other sites More sharing options...
mtorbin Posted May 11, 2009 Author Share Posted May 11, 2009 I'll definitely give that a go. What's odd, and somewhat sad, is that I checked this file in other text editors (both PC and Mac) and this is the ONLY one that displays double carriage returns. I'm using TextWrangler by Bare Bones. I've used this particular text editor for many years without issue. I wonder why THIS script created THIS problem. Anyways, I'm going to try your suggestion and report back. I hate to just walk away from a problem and write it off as a "software bug" without being sure. - MT Quote Link to comment https://forums.phpfreaks.com/topic/157709-whats-really-going-on-with-fwrite/#findComment-831812 Share on other sites More sharing options...
mtorbin Posted May 11, 2009 Author Share Posted May 11, 2009 In the hex editor, all of the affected areas contain: 0D 0A 20 20 - MT Quote Link to comment https://forums.phpfreaks.com/topic/157709-whats-really-going-on-with-fwrite/#findComment-831825 Share on other sites More sharing options...
Mchl Posted May 11, 2009 Share Posted May 11, 2009 http://en.wikipedia.org/wiki/Newline 0D0A is Windows specific newline character. Now, don't ask me how it get there... but since you're working on Mac, it might be seen as two consecutive newline characters... Just guessing. Quote Link to comment https://forums.phpfreaks.com/topic/157709-whats-really-going-on-with-fwrite/#findComment-831859 Share on other sites More sharing options...
mtorbin Posted May 11, 2009 Author Share Posted May 11, 2009 0D0A is Windows specific newline character. Now, don't ask me how it get there... but since you're working on Mac, it might be seen as two consecutive newline characters... Just guessing. that was sorta my thinking too because TextWrangler identifies a difference between "\r" and "\n". Thank you, at least I'm a lot closer then I was to figuring this one out. I think going forward I'm going to stick to Eclipse. - MT Quote Link to comment https://forums.phpfreaks.com/topic/157709-whats-really-going-on-with-fwrite/#findComment-831866 Share on other sites More sharing options...
Mchl Posted May 11, 2009 Share Posted May 11, 2009 If outputting xml is what you're after, why not try one of PHP extensions like simplexml or xmlwriter. No need to worry about whitespace, as they handle it for you. Quote Link to comment https://forums.phpfreaks.com/topic/157709-whats-really-going-on-with-fwrite/#findComment-831890 Share on other sites More sharing options...
mtorbin Posted May 11, 2009 Author Share Posted May 11, 2009 If outputting xml is what you're after, why not try one of PHP extensions like simplexml or xmlwriter. No need to worry about whitespace, as they handle it for you. Thanks. I've never used those but maybe it's time I did. - MT CORRECTION: Sorry, it's late in the day. I've used SimpleXML but in this case, it couldn't be done because the XML that I'm reading was non-standard so I had to use preg_match_all to grab chunks and rebuild. Quote Link to comment https://forums.phpfreaks.com/topic/157709-whats-really-going-on-with-fwrite/#findComment-831910 Share on other sites More sharing options...
Mchl Posted May 11, 2009 Share Posted May 11, 2009 You can still use it for output Quote Link to comment https://forums.phpfreaks.com/topic/157709-whats-really-going-on-with-fwrite/#findComment-831923 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.