Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-10-2004, 05:52 PM
southplatte's Avatar
WebProWorld Veteran
 

Join Date: Jul 2003
Location: Colorado
Posts: 381
southplatte RepRank 1
Default Another PHP question (writing files)

Hello all,

I am currently developing a site for an elderly lady (in her 70s I think) and she needs to be able to update the content on her own (her preference on that one). The web site is an electronic version of a book, so it is purely textual content (exception is page header). The site navigation doesn't need changed, but the individual pages (chapters, one per page) do.

What I have done is organized the content into plain text files, then performed a PHP include() on them. Works great.

Then I created a form that opens the text file into a textarea in a form (dynamically populating the form with the text file content). I then can make any changes I wish to the text file, add HTML if I want and all goes smooth. The submit function actually calls the page that writes to the file, and displays the changes.

Only one problem I have no clue how to get around: In the text file, anywhere there are quotes or double quotes (' and ") it adds backslashes before them. Each time you edit the page, the number of backslashes doubles (the order is 1, 3, 6, 12 and so on).

Anyone know how to write to a text file using the POST vairables from a form, have it inlcude quotes and double quotes, but not add the backslashes?

I tried running the file through the stripslashes() function, but found out that didn't work (I think that only works on URLs??).

Any ways, if you need the code I have, just let me know.
Reply With Quote
  #2 (permalink)  
Old 08-11-2004, 07:14 AM
WebProWorld 1,000+ Club
 

Join Date: Jul 2003
Location: UK
Posts: 1,143
nickc RepRank 0
Default Re: Another PHP question (writing files)

A single escape character (\) preceding the character you are trying to print (such as \") should do the trick. To show the slash use \\

Nick
Reply With Quote
  #3 (permalink)  
Old 08-11-2004, 02:43 PM
southplatte's Avatar
WebProWorld Veteran
 

Join Date: Jul 2003
Location: Colorado
Posts: 381
southplatte RepRank 1
Default

Thanks for the reply Nick. I knew I could do the escape character, but I am working with well over one hundred pages of text that have numerous quotes in them and to go through it all (even using a find and replace) would take way to much time, so i was hoping there was somthing with PHP that I could do to recognize them, or otherwise stop adding the backslashes on the page edit.

Thanks again, and that may be well what I have to do, just checking to see if there was anything else I could do to save some time/effort on this one.
Reply With Quote
  #4 (permalink)  
Old 08-11-2004, 02:56 PM
redcircle's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Grand Rapids, MI USA
Posts: 553
redcircle RepRank 0
Default

include() will just do what it says.. include it. What you will need to is read the file into a variable and run stripslashes on the variable.
Code:
        if(file_exists($file))//$file is the full path and filename
        {
            $fd = fopen ($file, "r");
            while (!feof ($fd))
            {
                $buffer = fgets($fd, 4096);
                $lines[] = $buffer;
            }
            fclose ($fd);
            $text = stripslashes(implode($lines,''));
            
        }
$text now has the text file as a variable without slashes that you can echo into the textarea. I haven't tested this but it should work.
__________________
www.squitosoft.com - PHP development site. featuring Squito Gallery. a php driven photo gallery.
www.rgfx.net - Specializing in Internet solutions, including Html authoring, Interactive Web sites, 3D/2D Graphics and animation.
Reply With Quote
  #5 (permalink)  
Old 08-12-2004, 02:10 AM
southplatte's Avatar
WebProWorld Veteran
 

Join Date: Jul 2003
Location: Colorado
Posts: 381
southplatte RepRank 1
Default

redcircle,

I had tried the stripslashes(), but I didn't do it in the same manner, so I will try your suggestion. Thanks for the reply!
Reply With Quote
  #6 (permalink)  
Old 08-12-2004, 04:16 PM
southplatte's Avatar
WebProWorld Veteran
 

Join Date: Jul 2003
Location: Colorado
Posts: 381
southplatte RepRank 1
Default

Okay, I see how this will work, but how do I get the script to stop writting the slashes to the the text file in the first place? Can I run the file resource through stripslashes() before the fwrite()?

Each time I open a file, using fopen() and make changes using fwrite(), it doubles the amount of backslashes before the quotes in the phrases.
Reply With Quote
  #7 (permalink)  
Old 08-12-2004, 07:08 PM
redcircle's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Grand Rapids, MI USA
Posts: 553
redcircle RepRank 0
Default

if you want to have the text files not contain the slashed you will need to stripslashes() before you write the file. You then will need to addslashes when you read the file.

here's some info from the docs.

magic_quotes_gpc boolean

Sets the magic_quotes state for GPC (Get/Post/Cookie) operations. When magic_quotes are on, all ' (single-quote), " (double quote), \ (backslash) and NUL's are escaped with a backslash automatically.

if you want you can turn it off with set_magic_quotes_runtime() http://us4.php.net/manual/en/functio...es-runtime.php
__________________
www.squitosoft.com - PHP development site. featuring Squito Gallery. a php driven photo gallery.
www.rgfx.net - Specializing in Internet solutions, including Html authoring, Interactive Web sites, 3D/2D Graphics and animation.
Reply With Quote
  #8 (permalink)  
Old 08-13-2004, 12:38 PM
southplatte's Avatar
WebProWorld Veteran
 

Join Date: Jul 2003
Location: Colorado
Posts: 381
southplatte RepRank 1
Default

thank you again for the help I think I got it now!
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0