On Fri 20 Jul 07 04:21, ahlist wrote:
> On 7/19/07, ahlist <[EMAIL PROTECTED]> wrote:
> > A libarary I'm using (the cybersource api if it helps any) is dying
> > when I pass it "extended" chars - such as bjorn (two dots over the
> > o - not sure of the actual name of this char -sorry).
> >
> > For some reason, the newest version of cybersourc's api aborts on
> > this input.
> >
> > Can anyone recommend a quick way to strip/convert those chars out
> > before I pass it to cybersources lib?
> >
> > I store the data as a varchar in mysql and pull it out in a query.
> >
> > Thanks for ANY advice. I need to get some sort of fix for this
> > asap.
>
> I should add that I'm not using mbyte extension.
>
> Is there any transformation or regex that could replace anything
> outside of a-zA-z with another char. I don't need this to be exact.
> The db will still hold the original, correct chars. I just need to
> feed something to the cybersource lib that is all a-zA-Z
>
> Thanks in advance.
do a $somestring = cleanconvertaccents($somestring);
then pass it over to your function. was trying to do the same and found
nice examples in php.net and other places on the web.
// i got this function from the web.. converts accents into their lower
ascii base chars. converted it a bit to handle more characters
// credits to opensource! got this from the strtr docs on php.net
// thank you -sven (www.bitcetera.com)
// It does accents and umlauts, but also ligatures and runes known to
ISO-8859-1
function cleanconvertaccents($str,$escapeapostrophes=false) {
$str = cleanutfstrtranslate($str,$escapeapostrophes);
$str = htmlentities($str);
//$newstr = preg_replace("/&([a-z])[a-z\d]+;/i","$1",$str);
$newstr = preg_replace("/(&#\d\d\d;)/i","$1",$str);
$newstr = preg_replace("/:/","",$newstr);
return $newstr;
}
function cleanutfstrtranslate($str,$escapeapostrophes=false) {
$badwordchars=array(
"\xe2\x80\x98", // left single quote
"\xe2\x80\x99", // right single quote
"\xe2\x80\x9c", // left double quote
"\xe2\x80\x9d", // right double quote
"\xe2\x80\x94", // em dash
"\xe2\x80\xa6" // elipses
);
if ($escapeapostrophes) {
$fixedwordchars=array( "\\'", "\\'", '\\"', '\\"', '-', 'o'); }
else { $fixedwordchars=array( "'", "'", '\"', '\"', '-', 'o'); }
$str=str_replace($badwordchars,$fixedwordchars,$str);
if ($escapeapostrophes) {
$str= strtr($str, array("\x92"=>"\\'"));
}
$str =
strtr($str,
"\x91\x92\x93\x94\x96\xA1\xAA\xBA\xBF\xC0\xC1\xC2\xC3\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1"
."\xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD\xE0\xE1\xE2\xE3\xE5\xE7\xE8\xE9\xEA\xEB\xEC"
."\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8\xF9\xFA\xFB\xFD\xFF",
"\"'\"\"-!ao?AAAAACEEEEIIIIDNOOOOOUUUYaaaaaceeeeiiiidnooooouuuyy");
$str= strtr($str,
array("\xC4"=>"Ae", "\xC6"=>"AE", "\xD6"=>"Oe", "\xDC"=>"Ue", "\xDE"=>"TH",
"\xDF"=>"ss",
"\xE4"=>"ae", "\xE6"=>"ae", "\xF6"=>"oe",
"\xFC"=>"ue", "\xFE"=>"th","\x85"=>"..."));
return($str);
}
--
Eddie Dunckley - [EMAIL PROTECTED] - Realtime Travel Connections
IBE Development, www.rttc.co.za, cell 083-379-6891, fax 086-617-7831
Where 33deg53'37.23"S 18deg37'57.87"E Cape Town Bellville Oakdale ZA
random quote: "Courage is grace under pressure."
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php