Solved

Converting Double Quotes

Posted on 2008-06-18
3
214 Views
Last Modified: 2010-04-21
See example URL. Enter anything surrounded in double quotes, for example, "this is a test". Click "Do It". See the result.

I don't want php to automatically insert the escape (\) before the ". How can that be avoided?

See attached code for php in 2nd script.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
function elim_quotes($x) {
	$res = "";
	$n = strlen($x);
	for ($i = 0; $i < $n; $i++) {
		$ch = substr($x,$i,1);
		if ($ch == chr(34)) {
			$res = $res . "``";
		} else {	
			if ($ch == chr(39)) {
				$res = $res . "`";
			} else {
				$res = $res . $ch;	
			}
		}
	}
	return $res;
}				
?>
<html>
<head>
	<title>Test elim quotes</title>
</head>
 
<body>
Value from form = <? print $val; ?><br>
<? $newval = elim_quotes($val); ?>
Converted value = <? print $newval; ?><br>
 
 
</body>
</html>

Open in new window

0
Comment
Question by:Richard Korts
[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
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 21814288
stripslashes()
<?php
function elim_quotes($x) {
$x = stripslashes($x);
	$res = "";
	$n = strlen($x);
	for ($i = 0; $i < $n; $i++) {
		$ch = substr($x,$i,1);
		if ($ch == chr(34)) {
			$res = $res . "``";
		} else {	
			if ($ch == chr(39)) {
				$res = $res . "`";
			} else {
				$res = $res . $ch;	
			}
		}
	}
	return $res;
}				
?>

Open in new window

0
 
LVL 82

Expert Comment

by:hielo
ID: 21814350
BTW: if you want to disable that ("auto-escaping") feature completely  throughout the server, in you php.ini file you would need this:
magic_quotes_gpc = Off
0
 

Author Closing Comment

by:Richard Korts
ID: 31468426
Great, thanks!
0

Featured Post

Industry Leaders: 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

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.  …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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…
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.

751 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