Solved

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

Posted on 2006-07-03
6
293 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
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now