Jump to content

Recommended Posts

Hey guys,

 

Pretty new to the whole file writing functions within PHP and i was looking for some help. Basically i have a text file that looks like this:

 

<bt>600</bt>
<iregno>123123</iregno>

<users>
<un>2</un>

<u1>
<n>Username</n>
<ema>username@domain.com<ema>
<s>password</s>
<t>user type</t>
<p>profile name</p>
<cat>000000000000000000000000000000000</cat>
</u1>

<u2>
<n>Username</n>
<ema>username@domain.com<ema>
<s>password</s>
<t>user type</t>
<p>profile name</p>
<cat>000000000000000000000000000000000</cat>
</u2>

and so on

</users>

 

Now i run this big user edit function where im reading in their details and displaying them in forms and so on. They then edit the form fields and i read them back in using $POST. That's the easy part. What i then want to do is re-write a section of my text file.

 

I have a variable that tells me what user i need to re-write the details for, i also have all the new details that i need to replace the old ones with. So, in logical terms, what i need to do is move my file pointer to that section of the file:

 

read in $userToEdit variable -> output of variable is <u1> -> move file pointer to next line (<n>username</n>) and let me rewrite the next 6 lines therefore leaving the pointer at </u1>

 

I hope that makes sense. Just basically want to rewrite the text that is there, not append/add.

 

Any suggestions?

Cheers..

Ok i figured out that i cant just open the file, store it as an array, and then change the variables in the array. All i need to do now is to write the array back to the file. But obviously:

 

fwrite($fp, $arrayData)

 

will not work. Any pointers on how to write an array and all of its data to a text file?

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.