2

Is there a string functions which replaces all the awkward characters, like

Hellö becomes Hello,

Or do i need the following strtr function, and put all the awkward characters in the...?

$addr = strtr($addr, "äåö", "aao"); 
1
  • Can you specify more precisely what you mean by "awkward characters"? Commented Dec 15, 2010 at 22:44

1 Answer 1

4

I'm assuming by "awkward characters" you mean anything that is not ASCII. If so, then try iconv:

$addr = iconv('UTF-8', 'ASCII//TRANSLIT', $addr);

The first argument is the character set of the input string.

$addr = "Hellö";
echo $addr . "\n";
$addr = iconv('UTF-8', 'ASCII//TRANSLIT', $addr);
echo $addr . "\n";

Output

Hellö
Hello

See it run at ideone.

Sign up to request clarification or add additional context in comments.

7 Comments

don't do this ... if the text contains valid UTF-8, it will get converted as well
@ajrael: What this does is to take the characters that are not valid ASCII and convert them as best as possible to valid ASCII.
Yup, at the meantime, it also replace valid UTF-8 to ?. However, is depend on OP environment setting.
Is it safe then...? What to do...? Regards!
If you page encoding is iso-8859-*, please go ahead
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.