473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

php esacping single quotes

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
3 6377
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sinister | last post by:
The examples in the online manual all seem to use double quotes, e.g. at http://us3.php.net/preg_replace Why? (The behavior is different with single quotes, and presumably simpler to...
6
by: Cyrus D. | last post by:
Hi guys, I haven't done that much research on this topic but it seems I can use either the single quotes or the double quotes. SInce I am so used to C(++) I prefer the double quotes and am...
11
by: Jakanapes | last post by:
Hi all, I'm looking for a way to scan a block of text and replace all the double quotes (") with single quotes ('). I'm using PHP to pull text out of a mySQL table and then feed the text into...
5
by: Joel | last post by:
Hi, I incorporated a function in my code that whenever I use a string variable in an sql statement if the string contains a single quote it will encase it in double quotes else single quotes. ...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
4
by: (PeteCresswell) | last post by:
Is his just a flat-out "No-No" or is there some workaround when it comes time for SQL searches and DAO.FindFirsts against fields containing same? I can see maybe wrapping the value searched for...
3
by: Fred Flintstone | last post by:
I'm writing an app in VB.Net that talks to MS SQL Server 2000. The problem is that when someone enters a single quote into a field, I get SQL errors. I've looked this up and its recommended that...
4
by: Justin Fancy | last post by:
Hi everyone, I need to replace all instances of a double quote(") with two single quotes('') in a text file. I already have some replacements of strings going on, but I tried this one, but the...
4
by: Michael Yanowitz | last post by:
Hello: If I have a long string (such as a Python file). I search for a sub-string in that string and find it. Is there a way to determine if that found sub-string is inside single-quotes or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.