Jump to content

Handling Special Characters


nerohj

Recommended Posts

Hello all,

 

I have a database and some fields have foreign characters in them (umlauts, haceks, etc.). I need to extract the text, and send emails with the characters in-tact.

 

Currently this is what happens:

 

Original text in database:

Quelqu'un vous contactera aussitôt que possible.

 

Same message when received in the email:

Quelqu'un vous contactera aussitôt que possible.

 

Here is the PHP code which extracts the text:

$query = "SELECT * FROM pages WHERE confirmail_subject <> '';";
$contact =& $DBH->getRow ($query);
if (PEAR::isError ($contact)) { die ($contact->getMessage() . " $query"); }

if ($contact['confirmail_subject'] && $contact['confirmail_body']) {
    $mail_sent = mail($target_email, $contact['confirmail_subject'], $contact['confirmail_body'], "From: {$source_email}");
}

 

Not sure what's up here, as I've never really had to pay much attention to non-english characters before now. :)

 

Thanks in advance for any guidance.

Cheers,

Nick

Link to comment
Share on other sites

Hi tmallen,

 

Thanks for your reply. The UTF8 method sounds like the right way to go in the long run, but this is an already developed application that I have been tasked with maintaining, so right now I'm just looking for the quick fix.

 

With that in mind, I looked into htmlentities(), however this is for escaping special characters. The idea is I've already got the correct string in the database. The special characters show up fine there. It's when I extract it from the database that the special characters get messed up, running the result of the query through htmlentities() just escaped the bad characters.

 

$query = "SELECT * FROM pages WHERE confirmail_subject <> '';";
$contact =& $DBH->getRow ($query);
if (PEAR::isError ($contact)) { die ($contact->getMessage() . " $query"); }

if ($contact['confirmail_subject'] && $contact['confirmail_body']) {
    $mail_sent = mail($target_email, htmlentities($contact['confirmail_subject']), $contact['confirmail_body'], "From: {$source_email}");
}

 

The email output is like so:

Quelqu'un vous contactera aussitôt que possible.

 

 

How can I pull the correct string from the database is it is without garbling it?

 

Sorry if I'm missing something obvious here, as I said, completely new to dealing with special characters.

 

Thanks,

Nick

 

 

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.