Annoying backslashes

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
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Annoying backslashes

Post by djwk »

Hello,

Here's my code:

Code: Select all

<?php
$msg = $_POST['msg'];

	$file = "display.txt";
	$fp = fopen("$file", "w");
	fwrite($fp, $msg);
	fclose($fp);
?>
If I type a ' or a " into the 'msg' textbox on the previous form it prints it as \' or \"

How do I stop this happenening?
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

that easy :D stripcslashes()
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Post by djwk »

I did

Code: Select all

stripcslashes($msg);
and it still displays the backslash
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

can you show the piece of code where you strip slashes?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

you gotta strip them out when outputting, when you write to the file for whatever reason it adds slashes automatically
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Post by djwk »

nevermind, i forgot to put the '$msg =', working now, thanks for ur help
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

try stripslashes() (not cslashes) dunno if it'd make a difference

but your quotes are being escaped most likely because you have magic quotes gpc enabled

so, either

ini_set("magic_quotes_gpc","Off");

or

$msg = stripslashes($_POST['msg']);
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Post by djwk »

Don't you read any other post other than the first?

Quote from my last post:
working now
....
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

djwk wrote:Don't you read any other post other than the first?

Quote from my last post:
working now
....
obviously I did, given the data contained in my post.
i must've looked over your final post
word of advice, that attitude won't get you much help on the boards.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply