By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,068 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

php esacping single quotes

P: n/a
Hello

I've been trying to figure this problem out for quite a while and I'm
having no joy.
I'll give you some background info, I'm creating a form and one of the
fields in the form is a big text area that I want to use to write to
a text file. This works fine but the problem is all the single quotes
are get escaped with slashes.

I want to write to the text file with out the quotes getting escaped,
I've tried htmlentities but that doesn't seem to work.
Here is a snippet of the code.

$Desc_file = date("dmYHis");
$Desc_new = htmlentities($desc, ENT_QUOTES);
$filePath = "/public_html/nsite/info";
$WriteToFile = fopen("$filePath/$Desc_file","w+");
fwrite ($WriteToFile, $Desc_new);
fclose ($WriteToFile);

Any ideas would be fantastic Thanks in advance for your help

Mudassar
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
mu******@aircandy.co.uk (mudassar) wrote:
I want to write to the text file with out the quotes getting escaped,
I've tried htmlentities but that doesn't seem to work.
Here is a snippet of the code.


Er?? Your previous post (yesterday) has been answered.

JOn
Jul 17 '05 #2

P: n/a
In message <86**************************@posting.google.com >, mudassar
<mu******@aircandy.co.uk> writes
Hello

I've been trying to figure this problem out for quite a while and I'm
having no joy.
I'll give you some background info, I'm creating a form and one of the
fields in the form is a big text area that I want to use to write to
a text file. This works fine but the problem is all the single quotes
are get escaped with slashes.

I want to write to the text file with out the quotes getting escaped,
I've tried htmlentities but that doesn't seem to work.
Here is a snippet of the code.

$Desc_file = date("dmYHis");
$Desc_new = htmlentities($desc, ENT_QUOTES);
$filePath = "/public_html/nsite/info";
$WriteToFile = fopen("$filePath/$Desc_file","w+");
fwrite ($WriteToFile, $Desc_new);
fclose ($WriteToFile);

Any ideas would be fantastic Thanks in advance for your help
I *think* this will help:

http://www.php.net/manual/en/function.stripslashes.php

I realised I have the same problem with a particular page, but haven't
tried the cure yet!

Mudassar


--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #3

P: n/a
mu******@aircandy.co.uk (mudassar) wrote in message news:<86**************************@posting.google. com>...
Hello

I've been trying to figure this problem out for quite a while and I'm
having no joy.
I'll give you some background info, I'm creating a form and one of the
fields in the form is a big text area that I want to use to write to
a text file. This works fine but the problem is all the single quotes
are get escaped with slashes.

I want to write to the text file with out the quotes getting escaped,
I've tried htmlentities but that doesn't seem to work.
Here is a snippet of the code.

$Desc_file = date("dmYHis");
$Desc_new = htmlentities($desc, ENT_QUOTES);
$filePath = "/public_html/nsite/info";
$WriteToFile = fopen("$filePath/$Desc_file","w+");
fwrite ($WriteToFile, $Desc_new);
fclose ($WriteToFile);

Any ideas would be fantastic Thanks in advance for your help

Mudassar


Hi Mudassar,

Here is the modified code to handle the escaped single quotes.

// Start of Code

$Desc_file = date("dmYHis");

if (get_magic_quotes_gpc())
$Desc_new = stripcslashes($desc);
else
$Desc_new = $desc;

$filePath = "/public_html/nsite/info";
$WriteToFile = fopen("$filePath/$Desc_file","w+");
fwrite ($WriteToFile, $Desc_new);
fclose ($WriteToFile);
// End of code
*Magic Quotes GPC* is a PHP_INI setting. When it is set ON all the
single quotes coming from any form are escaped with character \.
Default setting for the Magic Quotes GPC is ON.

Hope it will help....

-- Rahul
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.