2

Test string:

$s = "convert this: ";
$s .= "–, —, †, ‡, •, ≤, ≥, μ, ₪, ©, ® y ™, ⅓, ⅔, ⅛, ⅜, ⅝, ⅞, ™, Ω, ℮, ∑, ⌂, ♀, ♂ ";
$s .= "but, not convert ordinary characters to entities";
3
  • 3
    But what for? This shouldn't be necessary if the document is properly encoded. Commented Feb 25, 2011 at 23:01
  • @Pekka: My problem isn't render the data, my problem is store it. I can't change the db structure nor config fields. Commented Feb 25, 2011 at 23:21
  • 1
    If your database can't store non-ASCII characters, you need to fix the database, not kludge your data into some ad-hoc encoded format. Keep database strings in raw form. Commented Feb 26, 2011 at 9:47

3 Answers 3

11
$encoded = mb_convert_encoding($s, 'HTML-ENTITIES', 'UTF-8'); 

asssuming your input string is UTF-8, this should encode most everything into numeric entities.

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

1 Comment

@Marc B, You great, this is what I am looking for. much helpful
0

I did work on decoding ascii into html coded text (&#xxxx). https://github.com/hellonearthis/ascii2web

Comments

-1

Well htmlentities doesn't work correctly. Fortunately someone has posted code on the php website that seems to do the translation of multibyte characters properly

1 Comment

Give an example. It works for me and others.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.