PHP not have a function for XML-safe entity decode? Not have some xml_entity_decode?

后端 未结 6 1911
旧时难觅i
旧时难觅i 2020-12-17 02:20

THE PROBLEM: I need a XML file \"full encoded\" by UTF8; that is, with no entity representing symbols, all symbols enconded by UTF8, except the only 3 ones that are

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-17 02:52

    Try this function:

    function xmlsafe($s,$intoQuotes=1) {
    if ($intoQuotes)
         return str_replace(array('&','>','<','"'), array('&','>','<','"'), $s);
    else
         return str_replace(array('&','>','<'), array('&','>','<'), html_entity_decode($s));
    }
    

    example usage:

    echo '';
    

    also: https://stackoverflow.com/a/9446666/2312709

    this code used in production seem that no problems happened with UTF-8

提交回复
热议问题