Jump to content

My dbase returns £ as £


johnsmith153

Recommended Posts

My database is storing £ as £ - this is not ideal, but I don't want to change it now - as it would mean changing a lot of scripts.

 

It is easier to change the one script that pulls info from the db and uses it.

 

The text pulled from the dbase is then emailled, so I dont want to use htmlentities on it (ie to maintain <> etc.)

 

If I do:

$value = htmlentities($value, ENT_NOQUOTES, 'UTF-8');

$value = html_entity_decode($value, ENT_NOQUOTES, 'UTF-8');

...it works on screen, but not in the email for some reason.

 

Any ideas?

 

$value=str_replace("£","£",$value);

...also doesn't work

Link to comment
https://forums.phpfreaks.com/topic/155098-my-dbase-returns-%C2%A3-as-%C3%A2%C2%A3/
Share on other sites

That mean you don't use the same encoding as your database or database connection.

 

For the database you probably can change it with phpmyadmin or whatever other software you use to interact with database.

 

Set the database connection encoding (right after connection and select) :

<?php
...
mysql_query("SET NAMES 'utf8';", $connect) or die ("Unable to set names.");
mysql_query("SET CHARACTER SET 'utf8';", $connect) or die ("Unable to set charset.");
?>

 

To set the encoding in the html page :

<?php
header('Content-Type: text/html; charset=utf-8');
?>

This tell the browser/client what encoding you use into the http header, you must put this before anything else, including space or enter.

 

And you will need it inside the html too :

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

 

If you use UTF-8 everywhere it will work, but i'm not sure about the special chars that was inserted before you set everything in UTF-8.

 

Or you can use htmlentities() before storing it into the database, htmlentity only use ASCII characters and they will work no matter what charset/encoding you have.

 

For the email add this for text mail only :

Content-Type: text/plain; charset=UTF-8

or this for html email :

Content-Type: text/html; charset=UTF-8

You can see how it's done here : http://www.php.net/manual/en/function.mail.php

 

I wonder why it work...

$value = htmlentities($value, ENT_NOQUOTES, 'UTF-8');
$value = html_entity_decode($value, ENT_NOQUOTES, 'UTF-8');

Aren't supposed to do anything, basically you convert a variable from UTF-8 to UTF-8.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.