Handling apostrophes when generating HTML with PHP

前端 未结 5 774
慢半拍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:59

    You can use double quotes to surround the text:

    
    

    An even better way would be to replace the apostrophes with '.

    
    

    This is a more robust solution in case the text includes double quotes as well. You should replace all 's with 's and "s with "s.

    This can be easily done using htmlspecialchars(string $str). http://php.net/manual/en/function.htmlspecialchars.php

提交回复
热议问题