Converting fractions to html entities

随声附和 提交于 2019-12-01 02:13:38

问题


We've got some fraction information stored in the database, e.g. ¾ ½

Short of doing a search and replace, are there any inbuilt PHP functions that will automatically convert these to proper html entities?


回答1:


You can use the htmlentities() function. This will replace all special characters with their HTML equivalent. It should do the job your require.

Good question btw, +1.




回答2:


htmlentities.

But you probably don't need to. Serve your page in an encoding that includes them (UTF-8, ISO-8859-1) and you can include those as literal, unescaped characters.




回答3:


The answer is already given: use htmlentities(). In addition, the use of UTF-8 has been suggested, which of course is a really good idea. However, if you're planning on using htmlentities() on UTF-8 strings, use the following code (or you'll get weirdly encoded characters):

htmlentities($str, ENT_COMPAT, 'UTF-8')

As you can imagine, it sucks having to add the second and third argument all the time. For most projects I need htmlentities() in, I end up writing the a shortcut function, i.e.:

function he($str) { // shortcut function for htmlentities() with UTF-8 settings
 return htmlentities($str, ENT_COMPAT, 'UTF-8');
}



回答4:


try htmlentities()



来源:https://stackoverflow.com/questions/724926/converting-fractions-to-html-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!