Newbie fwrite text file question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mrpants
Forum Newbie
Posts: 2
Joined: Sat Sep 11, 2004 5:21 pm

Newbie fwrite text file question

Post by mrpants »

Sorry if this has been answered before somewhere... but it's a pain to actually search for it because of the character output.

Whenever I write to a text file using fwrite... instead of writing a single quotation mark... I get a backslash before every one. thusly:

<a href="http://www.targetwebsite" target="_blank">

Looks like

<a href=\"http://www.targetwebsite\" target=\"_blank\">

Huh?

I am using nl2br since I want people not to have to use html... but have it as an option. Am I doing something wrong... or do I need to find an replace all of these characters with a script?

It's a pain in the ass trying to search for \" as a problem in any search engine.

Any help would be much obliged.

pants
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

strip

Post by neophyte »

Did you try?

Code: Select all

<?php
stripslashes($string);

?>
mrpants
Forum Newbie
Posts: 2
Joined: Sat Sep 11, 2004 5:21 pm

Post by mrpants »

ACH! Thank you! Is there a way to have those slashes not even be written?

but yes... thank you.

pants
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Maybe

Post by neophyte »

The slashes are created by "magic slashes" a feature that is on by default and defined in your php.ini file. It adds slashes and removes slashes when pulling to and from databases. I just leave mine on and deal with it. If you're on a shared server you are probably stuck with it. There is a lot more you can read about it on the forum. Do a search for "magic slashes." I think the general opnion in this forum is that it's best to addslashes() and stripslashes() in your code rather than allowing "magic slashes" to do it for you.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[devnet]magicquotes[/devnet]
Post Reply