Solved

Converting Double Quotes

Posted on 2008-06-18
3
212 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 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

21 Experts available now in Live!

Get 1:1 Help Now