Jump to content

fopen() help.


Zipp425

Recommended Posts

I'm currently working on a javascript, xml, html, and php, based web application.
I was wondering if there was a way with php to open a file and delete a certain line and replace it. I am using PHP to create a xml file, and certain lines of that file will need to be deleted and replaced by changed data.

Any help or information on how to do this would be amazing. Let me know if you need more information.

Thanks!

zipp425@gmail.com
Link to comment
Share on other sites

Below are the three basic ways to open a file and the corresponding character that PHP uses.

    * Read: 'r'

Open a file for read only use. The file pointer begins at the front of the file.

    * Write: 'w'

Open a file for write only use. In addition, the data in the file is erased and you will begin writing data at the beginning of the file. This is also called truncating a file, which we will talk about more in a later lesson. The file pointer begins at the start of the file.

    * Append: 'a'

There are additional ways to open a file. Above we stated the standard ways to open a file. However, you can open a file in such a way that reading and writing is allowable! This combination is done by placing a plus sign "+" after the file mode character.

    * Read/Write: 'r+'

Opens a file so that it can be read from and written to. The file pointer is at the beginning of the file.

    * Write/Read: 'w+'

This is exactly the same as r+, except that it deletes all information in the file when the file is opened.

    * Append: 'a+'

This is exactly the same as r+, except that the file pointer is at the end of the file.

Open a file for write only use. However, the data in the file is preserved and you begin will writing data at the end of the file. The file pointer begins at the end of the file.
Link to comment
Share on other sites

Then you couldn't use a line number because the line number could change if the file is modified and added to. So, you'd have to use a key which basically would be the string of text. Can you post an example of what would need to be replaced periodically? Please be as specific as you can with your example including any XML tags (if applicable).



Link to comment
Share on other sites

Ive made it so the same data will always be on the same line.

I just need to figure out how to replace that specific line.

here is the xml file that is generated
[pre]
<?xml version='1.0' encoding='iso-8859-1'?>
<data>
<widgets>
<profile height='600px' width='800px' borderSize='2px' borderStyle='solid' borderColor='#000000' font='Arial, Helvetica, sans-serif' fontColor='#000000' fontSize='100%' backgroundColor='#ffffff' backgroundURL='' backgroundImgAlign='' backgroundImgRepeat='' misc=''/>
<textBox height='auto' width='300px' borderSize='1px' borderStyle='solid' borderColor='#000000' font='Arial, Helvetica, sans-serif' fontColor='#000000' fontSize='100%'  backgroundColor='#efefef' backgroundURL='' backgroundImgAlign='' backgroundImgRepeat='' misc='' />
<friendArea height='auto' width='400px' borderSize='1px' borderStyle='solid' borderColor='#000000' font='Arial, Helvetica, sans-serif' fontColor='#000000' fontSize='100%' backgroundColor='#efefef' backgroundURL='' backgroundImgAlign='' backgroundImgRepeat='' misc='' />
</widgets>
</data>
[/pre]

so basically what i need is to select the textBox line and replace it when a user changes the values.
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.