Jump to content

What's REALLY Going On with fwrite


mtorbin

Recommended Posts

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.