?
Solved

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

Posted on 2006-07-03
6
Medium Priority
?
308 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 80 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 160 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 80 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
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

765 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