-1

This code outputs UTF-8:

echo mb_detect_encoding("ø")

And this code outputs ASCII:

echo mb_detect_encoding("ø");

So, how do you convert UTF-8 to ASCII? For example: convert ø to &#248

1

2 Answers 2

4

ø is an HTML entity. It uses only ASCII characters, so it's detected as ASCII, yes. You just need to HTML encode your text:

echo htmlentities('ø', ENT_COMPAT, 'UTF-8');

This will output ø, but it's an equivalent named HTML entity.

I'm going out on a limb though and suggest that you don't really understand what you want exactly. Maybe you should read What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text and go from there.

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

Comments

0

Use htmlentities to achieve what you looking for

$myVar = 'ø';

$val = htmlentities($myVar);
echo $myVar;
// ø
echo mb_detect_encoding($myVar);
// UTF-8

echo $val;
// ø
echo mb_detect_encoding($val);
//ASCII

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.