PHP SimpleXML doesn't preserve line breaks in XML attributes

前端 未结 6 1378
自闭症患者
自闭症患者 2020-12-11 04:31

I have to parse externally provided XML that has attributes with line breaks in them. Using SimpleXML, the line breaks seem to be lost. According to another stackoverflow

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-11 04:58

    Here is code to replace the new lines with the appropriate character reference in that particular XML fragment. Run this code prior to parsing.

    $replaceFunction = function ($matches) {
        return str_replace("\n", "
    ", $matches[0]);
    };
    $xml = preg_replace_callback(
        "/

提交回复
热议问题