Solved

Single Quote Escape (\') Insertion Problem while writing and reading back a text file.   How to handle?

Posted on 2006-07-03
6
302 Views
Last Modified: 2013-12-12
Hello!    Everyone, I have a problem of BACK SLASH  INSERTION.

I am developing a Blog or Comment submission interface through Web_PHP.   Since I am dealing not only English but also other languages, I use UTF-8 as default charcter set at Apache.     I used a simple functions to write and read the UTF-8 text files.  

   fwrite();    and    readfile($filename);

Here comes a problem.   All single quotes are modified to have back slash (\), and each time read and write that text, back slash are increasingly inserted.   See example below.    

   Qu\'est ce que s\'est passé.
   Alors les résultats de recherche n\'ont plus le lien d\'agrafes de multimédia.

How to stop inserting those extra slashes?   Suggestion please!!    Help!
0
Comment
Question by:mkido
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 35

Assisted Solution

by:Raynard7
Raynard7 earned 20 total points
ID: 17034641
These back slashes are just escaped

You can use the stripslashes function (http://au.php.net/manual/en/function.stripslashes.php)
for example;
<?php
$str = "Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);
?>

to strip the slashes.
0
 
LVL 3

Accepted Solution

by:
NewJorg earned 40 total points
ID: 17036300
I assume that you read the file, show it in a form, edit the text in the browser and send it to the server which writes it back to the file?

then you should turn off the magic_quotes_gpc in php.ini. If you cant change it the suggestion from Raynard7 on the userinput will do fine.
0
 
LVL 20

Assisted Solution

by:Muhammad Wasif
Muhammad Wasif earned 20 total points
ID: 17041678
Its better to use stripslashes() in this way.

I am modifiying Raynard7's example
<?
$str = "Is your name O\'reilly?";

//first check if u need to remove the slashes or not
// by doing this you dont need to turn off the magic_quotes_gpc in php.ini
if(get_magic_quotes_gpc())
      echo stripslashes($str);
else
      echo $str;
?>

for more info http://www.php.net/get_magic_quotes_gpc
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mkido
ID: 17043088
Hello everyone, thank you very much.  

I will soon try to see what will happen by turning off,

   magic_quotes_gpc in php.ini

then, get back here.     Then, I will try,

   stripslashes().

Thanks.
0
 

Author Comment

by:mkido
ID: 17044149
Dear wasifq,

tunring off
  magic_quotes_gpc    in php.ini
worked.     wonderful!
I saw that when fwrite() wrote down the french text, it aldreay inserted the slash (\) in front of quote (').   Thus, I think it is better to prevent the insertion while PHP writes text down.    

Regarding stripslashes(), let me try a little later.   Thanks.
0
 

Author Comment

by:mkido
ID: 17052561
Thank you,
  Raynard7,  NewJorg,  and wasifq:

stripslashes() works well too.   I prefer to turn off "magic_quotes_gpc" in "php.ini" file.    Thanks for your help!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
[form-control] Retain values after a POST action 21 68
assigning javascript variable to php variable 8 66
How do I speed up this PDO query 4 38
Php variable to be sent back 3 30
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question