XML 文件开头的字符


Characters at the start of xml file

´╗┐<?xml version="1.0" encoding="UTF-8"?>

如何在 php 中从上述字符串中删除"╗┐"?当我使用 file_get_content($file) 或 laravel 的 File::get($file) 时,我得到了它,在各种文本编辑器中打开文件时确实出现了所有特殊字符。

您可以使用

这样的preg_match来完成这项工作

$XML = '´╗┐<?xml version="1.0" encoding="UTF-8"?>';
preg_match("/<'?xml.*/", $XML, $matchs);
$newXML = $matchs[0];

演示中进行测试