 |

08-10-2004, 05:52 PM
|
 |
WebProWorld Veteran
|
|
Join Date: Jul 2003
Location: Colorado
Posts: 381
|
|
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.
|

08-11-2004, 07:14 AM
|
|
WebProWorld 1,000+ Club
|
|
Join Date: Jul 2003
Location: UK
Posts: 1,143
|
|
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
|

08-11-2004, 02:43 PM
|
 |
WebProWorld Veteran
|
|
Join Date: Jul 2003
Location: Colorado
Posts: 381
|
|
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.
|

08-11-2004, 02:56 PM
|
 |
WebProWorld Veteran
|
|
Join Date: Aug 2003
Location: Grand Rapids, MI USA
Posts: 553
|
|
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.
|

08-12-2004, 02:10 AM
|
 |
WebProWorld Veteran
|
|
Join Date: Jul 2003
Location: Colorado
Posts: 381
|
|
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!
|

08-12-2004, 04:16 PM
|
 |
WebProWorld Veteran
|
|
Join Date: Jul 2003
Location: Colorado
Posts: 381
|
|
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.
|

08-12-2004, 07:08 PM
|
 |
WebProWorld Veteran
|
|
Join Date: Aug 2003
Location: Grand Rapids, MI USA
Posts: 553
|
|
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.
|

08-13-2004, 12:38 PM
|
 |
WebProWorld Veteran
|
|
Join Date: Jul 2003
Location: Colorado
Posts: 381
|
|
thank you again for the help I think I got it now!
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|