note 14482 deleted from function.strtr by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: persiflage2000 at yahoo dot com 

----

To replace unicode characters with their ascii equivalents, use

$my_string = strtr($my_string, $unicode_array);

using this array:

$unicode_array = array(
		"&#8211;" => "-",
		"&#8212;" => "-",
		"–" => "-",
		"&#8216;" => "'",
		"’" => "'",
		"&#8217;" => "'",
		"‘" => "'",
		"&#8230;" => "...",
		"…" => "...",
		"“" => "\"",
		"&#8220;" => "\"",
		"”" => "\"",
		"&#8221;" => "\"",
	);

It is important to note you need both the unicode contol character (&#8221;) AND its text equivalent (”).  For instance, text copied and pasted into your html form from M$ Word will have the control character, whereas the same text viewed in a browser and copied into your html form using drag-and-drop will have the text equivalent.

A pox on Redmond for the way M$ Word is set to convert all these characters to unicode equivalents by default.

Note: you can expand the array to get rid of accented characters too, but remember the same thing applies.  For example, both "&#352;" => "S" and "Š" => "S" should be added to the array.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.