How should I echo a PHP string variable that contains special characters?

前端 未结 4 1254
轻奢々
轻奢々 2021-01-17 09:05

I\'m trying to populate a form with some data that contains special characters (e.g. single quote, double quote,<,>,?,\",\"\".~,,!@#$%^&*()_+}{\":?<<>,./;\'[.]

4条回答
  •  Happy的楠姐
    2021-01-17 09:47

    If you want to display it

    echo htmlspecialchars($messge, ENT_QUOTES, 'UTF-8');
    

    That's what I usually do.

    Since the answers are difference:

    htmlentities-vs-htmlspecialchars is worth checking out.

提交回复
热议问题