Gossamer Forum
Home : General : Perl Programming :

encoding problem

Quote Reply
encoding problem
i had the following code to change a displayed ampersand to a plain one for saving in text database:
Code:
$tmp =~ s/&/&/g; # 01/22/2017 w3 validation for AT&T

then i had the following code to change the ampersand to w3 validation friendly one for display after retrieving record:

Code:
$array[$i] =~ s/&/&/g;
both worked fine. but now i'm having problem with double quotes. if someone enters double quotation marks in a text field, the record is saved with the quotation mark. but if the record is modified, the form interprets the quotation mark as the end of the field value and wipes out the record. i think i solved this problem before but have accidentally lost my fix. there must be a simple way to encode everything properly.

Quote Reply
Re: [delicia] encoding problem In reply to
Depending on your data, you could use boundary (\b)... so:

Code:
s/\b&//g;

Also, its good practice to escape & - so \& (in case perl tries to run it as a sub)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!