Terry Carnes
Terry Carnes

Reputation: 189

How can I convert ANSI Extended ASCII (Windows) to UTF-8 or html entities with PHP?

Possible Duplicate:
PHP Ansi to UTF-8

I have data that occasionally includes various ANSI Windows ASCII characters (i.e., x99 for TM, xA9 for copyright, xAE for registered trademark, etc). These characters do not display properly in web pages.

Is there a function in PHP that will allow me to automatically convert them properly? Or, do I have to have a ton of str_replace() calls that make each substitution separately? If I do have to use str_replace(), what is the proper way to match the ANSI code? I'm thinking something like:

$str = str_replace('/\x99','™',$str); // trademark symbol

Is there a better way?

Upvotes: 0

Views: 773

Answers (1)

Exostor
Exostor

Reputation: 133

Look at htmlentities

http://php.net/manual/en/function.htmlentities.php

It converts < to &lt;, ö to &ouml; etc...

Upvotes: 0

Related Questions