• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

Textarea problems with quotation

Hi E's, I write text in a html textarea and I save that text in my data base.
My problem is when I write something like:
<style type="text/css" media="screen">

When I save the contain of textarea the code above appear:
<style type=\"text/css\" media=\"screen\">

What php function I have to use to resolve the problem?

Regards, JC
0
Pedro Chagas
Asked:
Pedro Chagas
1 Solution
 
ukerandiCommented:
you can use wordwrap function or streplace function
0
 
psimationCommented:
When you want to display the content in your DB again, just pass it through stripslashes().
0
 
ukerandiCommented:
$text='<style type=\"text/css\" media=\"screen\">';

wordwrap($text, strlen($text), "\", true);
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ukerandiCommented:
$text='<style type=\"text/css\" media=\"screen\">';
 str_replace("\", "", "$text");
0
 
ukerandiCommented:
$text='<style type=\"text/css\" media=\"screen\">';
echo stripslashes($text);
0
 
Ray PaseurCommented:
This problem occurs because of multiple addslashes() or mysql_real_escape_string() functions applied to the data.  A common cause is a program that (correctly) escapes external data, but the program is run on a server with "magic quotes" in the configuration.  See this article for an explanation.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_6630-Magic-Quotes-a-bad-idea-from-day-one.html

The standard solution to the problem is a bit of a hack.  You can use stripslashes() on the data that is retrieved from the data base.  However if you control both the programming and the server, you can do it the right way, by turning off magic quotes and including your own escape sequences.  Don't try it the "right" way unless you are certain that your programming escapes all the external data correctly.

HTH, ~Ray
0
 
Ray PaseurCommented:
Sidebar note... The idea at ID:37029889 is not useful, because the construct "\" will create a parse error.  The backslash is an escape character.  It has to be doubled, in effect "escaping itself" if it is to be usable in PHP.  

You can see the program in action here; it does not remove the backslash characters.  It's a good idea to test the comments and proposed solutions that you find at EE.  Not all of our experts test their programming before they post, so you may find "interesting" results if you take the answers on face value.
http://www.laprbass.com/RAY_temp_ukerandi.php
<?php // RAY_temp_ukerandi.php
error_reporting(E_ALL);

// THE EXAMPLE FROM EE
$text='<style type=\"text/css\" media=\"screen\">';

// SEE http://php.net/manual/en/function.wordwrap.php
$x = wordwrap($text, strlen($text), "\\", true); // NOTE THAT THE SINGLE BACKSLASH CAUSES A PARSE ERROR

// SHOW THE ORIGINAL AND THE OUTPUT
echo "<pre>";
echo PHP_EOL;
echo htmlentities($text);
echo PHP_EOL;
echo htmlentities($x);

Open in new window

0
 
Pedro ChagasWebmasterAuthor Commented:
Hi Ray, I test your example and appear like this way:
<style type=\"text/css\" media=\"screen\">
<style type=\"text/css\" media=\"screen\">
0
 
Ray PaseurCommented:
Please read the post and the article at ID:37030356.  What you are testing is not "my" example.  It is the implementation of the bogus advice posted at ID:37029889.  The article explains how to handle issues caused by magic quotes.  It's worth understanding this -- magic quotes will be going away in a release of PHP that is coming to you soon, and you will want to be sure that none of your code relies on it before that release of PHP arrives.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now