[ale] [OT] .php logic problem

James P. Kinney III jkinney at localnetsolutions.com
Thu Aug 7 14:02:58 EDT 2003


IANAPHPE (I am not a PHP expert).

It looks to me that you need some logic code to handle the \' issue.

if character_before(') eq "\" do_nothing else sed s/'/\'/

Now the character_before function I can do in perl with string counting.
No clue how to do this in php.

On Thu, 2003-08-07 at 13:51, ChangingLINKS.com wrote:
> I have spent a lot of time on a weird php problem.
> I am trying to make sure that the ' character is always escaped in my 
> database. 
> 
> * I do not have the ability to configure the server. 
> * I do not know or care to know if magic_quotes_gpc is ON
> ’
> * htmlspecchar is not an option
> 
> I am using a form to update a field in the table.
> 1. If I use addslashes over and over like this:
> 		$description = addslashes($description);
> 		each time I click "update" it adds more and more slashes. (\\\\')
> 
> 2. If I stripslashes and addslashes like this:
> 		$description = stripslashes($description);
> 		$description = addslashes($description);
> 		this results in ' (no slashes) (why?)
> 
> 3. If I try getting fancy, I get lost like this:
> 		$description = stripslashes($description);
> 	 	$description = ereg_replace("'", "3edc1", $description);
> 	 	$description = ereg_replace("3edc1", "'", $description);
> 		$description = addslashes($description);
> 		this still results in ' (no slashes)
> 
> 4. My goal is to always end up with \' in the database after I update
> 		How do I do that?
> 
> The code just modifys the "description" string:
> 		$description = stripslashes($description);
> 	 	$description = ereg_replace("%", "percent", $description);
> 	 	$description = ereg_replace("\"", "", $description);
> //	 	$description = ereg_replace("'", "d4c1", $description);
> //	 	$description = ereg_replace("d4c1", "\\d4c1", $description);
> //	 	$description = ereg_replace("d4c1", "'", $description);
> //		$description = addslashes($description);
> 		$description = ereg_replace("w/", "3edc", $description);
> 	 	$description = ereg_replace("/", " ", $description);		
> 		$description = ereg_replace("3edc", "w/", $description);
> 		$description = strtolower( $description );
> 		$description = ereg_replace("&", "and", $description);	
> 
> Also related:
> Does anyone know how to change the open (and close) apostrophes into \'
> as well?
-- 
James P. Kinney III          \Changing the mobile computing world/
CEO & Director of Engineering \          one Linux user         /
Local Net Solutions,LLC        \           at a time.          /
770-493-8244                    \.___________________________./
http://www.localnetsolutions.com

GPG ID: 829C6CA7 James P. Kinney III (M.S. Physics) <jkinney at localnetsolutions.com>
Fingerprint = 3C9E 6366 54FC A3FE BA4D 0659 6190 ADC3 829C 6CA7 

 This is a digitally signed message part




More information about the Ale mailing list