0

I need to convert special characters like (®¢) to corresponding HTML entity numbers using PHP. Is there a function like htmlentities() to achieve this functionality? We need to populate the special symbols in an xsl:fo document. The best way to do this, is to store the special characters as entity numbers.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
vegeta
  • 297
  • 1
  • 14
  • @Neeraj: Those tags had nothing to do with the question. – Ry- Apr 12 '13 at 14:18
  • What is the goal of this unusual requirement? Why is htmlentities() not sufficient? – fabspro Apr 12 '13 at 14:21
  • @fabspro: If we use htmlentities, the output is an html entity name like ® which is not rendered by an xsl:fo document. Since, we are creating pdf using xsl:fo. We used html entity numbers instead of entity names.. and this worked. But we dont know how to convert a special symbol to corresponding entity number using php. – vegeta Apr 12 '13 at 14:25
  • 1
    Why not just use the right encoding for the document so you don’t need to? – Ry- Apr 12 '13 at 14:27

1 Answers1

3

Take a look at mb_encode_numericentity.

mb_encode_numericentity ($string, array (0x0, 0xffff, 0, 0xffff), 'UTF-8')

This will convert the entire string into numeric entities. You can change the ranges of characters that will be converted by modifying the members of the second argument to mb_encode_numericentity.

Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141