Generating XML document in PHP (escape characters)

前端 未结 10 993
难免孤独
难免孤独 2020-11-27 04:20

I\'m generating an XML document from a PHP script and I need to escape the XML special characters. I know the list of characters that should be escaped; but what is the corr

10条回答
  •  暖寄归人
    2020-11-27 05:11

     function replace_char($arr1)
     {
      $arr[]=preg_replace('>','>', $arr1); 
      $arr[]=preg_replace('<','<', $arr1);
      $arr[]=preg_replace('"','"', $arr1);
      $arr[]=preg_replace('\'','&apos', $arr1);
      $arr[]=preg_replace('&','&', $arr1);
    
      return $arr;
      }       
    

提交回复
热议问题