How to Construct xml in php with Special Characters?

后端 未结 2 408
南笙
南笙 2021-01-23 09:42

My user enters message with special characters as follows:

this is a test of &&, &&, % as well as \'\' "", &         


        
2条回答
  •  庸人自扰
    2021-01-23 10:13

    Try cleansing the input string using htmlspecialchars() (PHP spec) before adding it to the XML document which should give you the encoding you require.

    However if you are not constrained in the way that you create the XML document (i.e. you can do it in a way other than pure string manipulation) I would follow prostynick's solution as it is much more robust in the long term.

提交回复
热议问题