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.
Asked
Active
Viewed 765 times
0

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
-
1Why not just use the right encoding for the document so you don’t need to? – Ry- Apr 12 '13 at 14:27
1 Answers
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
-
@vegeta no problem, not sure why you need to do this though... see minitech's comment – Dagg Nabbit Apr 12 '13 at 15:43