1

How do you force PHP "htmlentities" to convert a special character to the entity number rather than to the entity name?

For example, convert É to &#201 rather than to &Eacute

I have searched with no answers.

SW_Cali
  • 383
  • 2
  • 17

1 Answers1

1

You don't can force PHP "htmlentities" to convert a special character to the entity number rather than to the entity name. Take a user function.

function htmlEntityNumber($char){
  $utf32char = mb_convert_encoding($char,"UTF-32BE","UTF-8");
  return "&#".unpack("N",$utf32char)[1] . ";";
}

//var_dump and echo only show an É
debug::write(htmlEntityNumber('É'));  
//string(5) ASCII   "&#201"
hassan
  • 7,812
  • 2
  • 25
  • 36
jspit
  • 7,276
  • 1
  • 9
  • 17