[FX.php List] Yet another annoying single-quotes problem

Erik Andreas Cayré erik at cayre.dk
Sat Apr 28 01:13:31 MDT 2007


Den 28/04/2007 kl. 8.35 skrev Bob Patin:

> Well, I finally did an end-run and fixed it by using this:
>
>
> $hospital = str_replace("’","'",$hospital);
>
> and it works fine... strange though that there's not an easier way...

I ran into the same problem a while ago.
After doing some research I ended up using the following:

// convert html encoded string to ISO-8859-1
	function unhtmlentities($string) {
	// replace numeric entities
		$string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))',  
$string);
		$string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string);
	// replace literal entities
		$trans_tbl = get_html_translation_table(HTML_ENTITIES);
		$trans_tbl = array_flip($trans_tbl);
		return strtr($string, $trans_tbl);
	}

I use the PHP mail function and emit a header:

$mailheaders = 'From: service at domain' . '
' .'Bcc: secretrecipient at otherdomain' . '
' . 'MIME-Version: 1.0' . '
' . 'Content-type: text/plain; charset=ISO-8859-1' . '
' . 'Content-Transfer-Encoding: quoted-printable'

This works great for me, and catches all odd characters, assuming  
they're encoded in hex.
I had a problem with the €(Euro) character, and tracked it down to  
being encoded as €
After changing it to € it works...

One limitation of this is that you may run into characters which are  
valid UTF-8 but do not exist in ISO-8859-1, but this problem is very  
unlikely within a North American setting...

Of course you may not want to use ISO-8859-1...
As Chris wrote, the stuff coming from FX is made ready to show on a  
webpage which is UTF-8.

I wonder if UTF-8 is a supported MIME encoding.
Does anyone know?


> On Apr 27, 2007, at 5:55 PM, Chris Hansen wrote:
>
>> Bob,
>>
>> FX.php tries to be smart by encoding special characters as HTML  
>> entities.  It you want plain text, try using the PHP function  
>> html_entity_decode() on the chunk that you want decoded.  HTH
>>
>> --Chris Hansen
>>   FileMaker 8 Certified Developer
>>   FileMaker 7 Certified Developer
>>   Creator of FX.php
>>   "The best way from FileMaker to the Web."
>>   www.iViking.org
>>
>>
>> On Apr 27, 2007, at 4:19 PM, Bob Patin wrote:
>>
>>> I get the feeling I've asked the same question 10 times, but I  
>>> don't think i've had this problem in this way yet:
>>>
>>> I'm adding some email functionality to a client's site, and when  
>>> I send myself a test email, I get this:
>>>
>>> St. Robert’s Hospital
>>>
>>> instead of
>>>
>>> St. Robert's Hospital
>>>
>>> I tried using STRIPSLASHES (which I knew was wrong, but I tried  
>>> anyway), and I tried HTMLENTITIES too; is there a command that  
>>> would prevent this when I'm sending a plain-text email?
>>>
>>> Thanks,
>>>
>>> Bob Patin
>>> Longterm Solutions
>>> bob at longtermsolutions.com
>>> 615-333-6858
>>> http://www.longtermsolutions.com
>>>
>>>   CONTACT US VIA INSTANT MESSAGING:
>>>      AIM or iChat: longterm1954
>>>      Yahoo: longterm_solutions
>>>      MSN: tech at longtermsolutions.com
>>>      ICQ: 159333060
>>>
>>>
>>>
>>> _______________________________________________
>>> FX.php_List mailing list
>>> FX.php_List at mail.iviking.org
>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>
>>
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list



---
Erik Andreas Cayré
Spangsbjerg Møllevej 169
6705 Esbjerg Ø

Privat Tel: 75150512
Mobil: 40161183

---
»Kun p....sure mennesker kan ændre verden. Innovation skabes ikke af  
'markedsanalyse', men af folk, der er afsindigt irriterede over  
tingenes tilstand «
--Tom Peters

»Hvis du ikke kan forklare det simpelt, forstår  du det ikke godt nok.«
-- Albert Einstein

»Hvis du ikke har tid til at gøre det rigtigt, hvornår vil du så have  
tid til at lave det om?«
-- John Wooden, basketball coach




More information about the FX.php_List mailing list