Jump to content

PLEASE help with stripping out accented international characters


vozzek

Recommended Posts

Hi all!

 

I have a programming question that's been plaguing us for a while now, and was hoping there was a php solution to it.

 

Our retail site gets a lot of international customers who enter special accented characters in their names and addresses.  When this happens, any of these characters going through my payment gateway end up throwing an error, and the customer has to re-enter their name/address without these characters if they want the sale to go through successfully.

 

Needless to say, I'm losing a lot of customers this way.  I wrote some php code to strip out these characters, but the problem is that once they get passed from one page to the other?  They're already messed up with all kinds of special character crap as html/UTF-8 whatever the hell tries to convert them.  My php code that would strip these characters out no longer applies, because the variables now contain all kinds of nightmarish control characters (like the reverse diamond with the upside down question mark in it).

 

Here's my php code so you can see what I'm talking about:

 

<?php
$search = explode(",","Â,Ã,Ä,À,Á,Å,Æ,Œ,Ç,È,É,Ê,Ë,Ì,Í,Î,Ï,Ð,Ñ,Ò,Ó,Ô,Õ,Ö,Ø,Ù,Ú,Û,Ü,Ý,Þ,ß,à,á,â,ã,ä,å,æ,ç,œ,è,é,ê,ë,ì,í,î,ï,ð,ñ,ò,ó,ô,õ,ö,ø,ù,ú,û,ü,ý,þ,ÿ");
$replace = explode(",","A,A,A,A,A,A,AE,OE,C,E,E,E,E,I,I,I,I,D,N,O,O,O,O,O,O,U,U,U,U,Y,P,B,a,a,a,a,a,a,ae,c,oe,e,e,e,e,i,i,i,i,o,n,o,o,o,o,o,o,u,u,u,u,y,b,y");

$last_name = str_replace($search, $replace, $last_name);
$address_1 = str_replace($search, $replace, $address_1);
$address_2 = str_replace($search, $replace, $address_2);
$city = str_replace($search, $replace, $city);
$state = str_replace($search, $replace, $state);
$zip_code = str_replace($search, $replace, $zip_code);
$country = str_replace($search, $replace, $country);
$bill_first_name = str_replace($search, $replace, $bill_first_name);
$bill_last_name = str_replace($search, $replace, $bill_last_name);
$bill_address_1 = str_replace($search, $replace, $bill_address_1);
$bill_address_2 = str_replace($search, $replace, $bill_address_2);
$bill_city = str_replace($search, $replace, $bill_city);
$bill_state = str_replace($search, $replace, $bill_state);
$bill_zip_code = str_replace($search, $replace, $bill_zip_code);
$bill_country = str_replace($search, $replace, $bill_country);
?>

 

This works great, as long as I already have the accented characters within the variables.  But since these variables are being passed (via inputs from a <form>) from the previous page, the accented characters have already been changed into wacky control characters.

 

What I think I need is some javascript.  That way I can change the fields AS the customers enter the information.  Maybe I need to do the search/replace upon form submission, BEFORE we go through to the verification page (where my php code resides)?

 

I found something to do with javascript replacment here, at this url:  http://www.w3schools.com/jsref/jsref_replace.asp

 

Is this what I need?  How would you strip these characters from your fields when the customer is entering their name, address,province and country?

 

My javascript variables look like: frm.first_name.value, frm.last_name.value, etc...

 

Thanks in advance for the help!  I'm really at a loss as to how to fix this.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.