Handling apostrophes when generating HTML with PHP

前端 未结 5 750
慢半拍i
慢半拍i 2020-12-22 02:13

I am generating radio buttons based on an XML config values. Sometimes they have apostrophes in the text. When manipulating this data in PHP, I seem to lose everything after

5条回答
  •  醉梦人生
    2020-12-22 02:48

    use htmlspecialchars():

    
    

    It's explicitly intended to allow safe insertion of arbitrary text into html without 'breaking' the html. Note the 'ent_quotes' option. By default htmlspecialchars will only handle <>", but since you're using ', you need the option to tell htmlspecialchars to handle those too.

提交回复
热议问题