Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 12-02-2003, 05:59 AM   #1 (permalink)
NirTivAal
Registered User
 
Join Date: Oct 2003
Posts: 11
NirTivAal is on a distinguished road
Double quotes in fwrite

Is there any way that I can get frwite to write double quotes (") without screwing up?

Whenever it encounters a double quote as part of a string it just stops writing (like you'd expect it to), but I can't figure out a way to get it to write a double quote properly. I've tried addslashes, but it had no effect.
NirTivAal is offline   Reply With Quote
Old 12-02-2003, 06:16 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,505
sde is on a distinguished road
you need to escape special characters by putting a \ before them.

for example:
PHP Code:
<?
print("this is how you would print a string with \"double quotes\".";
?>
the same should apply for fwrite.

hope this helps!
__________________
Mike
sde is offline   Reply With Quote
Old 12-02-2003, 06:24 AM   #3 (permalink)
NirTivAal
Registered User
 
Join Date: Oct 2003
Posts: 11
NirTivAal is on a distinguished road
Isn't that what the addslashes function should be doing?
NirTivAal is offline   Reply With Quote
Old 12-02-2003, 07:52 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,505
sde is on a distinguished road
depends how you're using it.

try my suggestion, let me know if it works.

then try posting your code with addslashes. maybe we can help you troubleshoot that function and the way you're using it.
__________________
Mike
sde is offline   Reply With Quote
Old 12-02-2003, 09:43 AM   #5 (permalink)
NirTivAal
Registered User
 
Join Date: Oct 2003
Posts: 11
NirTivAal is on a distinguished road
dfsg dfgdf g dfsg \"sfdg sfdg adff da\" avfdscewsc a.

Becomes:

dfsg dfgdf g dfsg \\

Here's essentially what I'm trying to do:
User has a <textarea> field to enter text into. This text is written to a file (with fopen, fwrite).
But you can see what happens with double quotes above (addslashes wasn't used at this time)
NirTivAal is offline   Reply With Quote
Old 12-02-2003, 09:52 AM   #6 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
hrm, works for me.

Code:
[joe@portia test]$ php -q
<?
$f = fopen("blah.txt", "w");
$s = "this is a \"quoted\" string\n";
fwrite($f, $s);
fclose($f);
?>
[joe@portia test]$ 
[joe@portia test]$ cat blah.txt 
this is a "quoted" string
[joe@portia test]$
can you provide a real code example that doesn't work?
joe_bruin is offline   Reply With Quote
Old 12-03-2003, 06:37 AM   #7 (permalink)
NirTivAal
Registered User
 
Join Date: Oct 2003
Posts: 11
NirTivAal is on a distinguished road
OK, here's essentially what I'm doing. There's other stuf that goes on that's unrelated to writing the file

PHP Code:
$article addslashes($article)
$full_article "<h2>$title</h2>\nBy: <a href=\"mailto:$email\">$name</a><br />\n$date<br /><br />\n$article\n<br /><br /><span class=\"final\"><b>Final grade: $rating</b></span>";
$file fopen("$dir/$articlenum.php""w");
fwrite($file$full_article);
fclose($file); 
The variables $title, $article, and $rating, are all submitted by the user.
Because these people won't know any HTML or PHP, I can't rely on them to escape characters themselves (not that it works that way anyways)
The fwrite command works perfectly fine as long as you don't use the double quotes. Using addslashes doesn't seem to be making a difference.
NirTivAal is offline   Reply With Quote
Old 12-03-2003, 10:05 AM   #8 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
1) why are you using addslashes()? that is only for escaping special characters for sql.

2) try writing this string: "quote \" test"
does it work? if so, your problem is not fwrite. i'm guessing you have some sort of automatic quote escaping running on submitted user data (magic_quote_runtime or similar) that's screwing up your strings. print out your string, so you can see what you're really trying to fwrite.
joe_bruin is offline   Reply With Quote
Old 12-08-2003, 08:13 AM   #9 (permalink)
NirTivAal
Registered User
 
Join Date: Oct 2003
Posts: 11
NirTivAal is on a distinguished road
The problem was with the variables, not fwrite. I fixed it, but damned if I know how.

Thanks for your help, guys.
NirTivAal is offline   Reply With Quote
Reply

Bookmarks

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macintosh Quotes? Admin PHP 5 06-04-2004 03:47 PM
Magic Quotes Epsilon PHP 2 01-16-2004 06:52 PM
fwrite() issues MysticalMatt517 PHP 2 12-19-2003 11:27 PM
Help Please (Need help by Monday 29th of September!) CoW Standard C, C++ 12 10-02-2003 09:38 AM


All times are GMT -8. The time now is 05:30 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting