The characters 
indicate that the document was saved with "UTF-8 with GOOD", when you were supposed to save "UNWELL".
How to resolve in the application
Note: in the examples I used simplexml_load_string
, but both he and the simplexml_load_file
returns a SimpleXMLElement
:
SimpleXMLElement
simplexml_load_string ( string $data [, string $class_name = "SimpleXMLElement" [, int $options = 0 [, string $ns = "" [, bool $is_prefix = false ]]]] )
I have no way to state which document it is, you can try to decode the XML content before "parse":
$data = file_get_contents($url);
$data = utf8_decode($data);
$xml = simplexml_load_string($data);
...
$xml->asXML();
Or decode and encode again (if you have a problem with XML being UTF-8 in the header):
$data = file_get_contents($url);
$data = utf8_decode($data);
$data = utf8_encode($data);
$xml = simplexml_load_string($data);
...
$xml->asXML();
You can choose to try using the trim
(this by the way was the only one that worked for me):
$data = file_get_contents('A.xml');
$data = trim($data); //Remove os espaçamentos incluindo o "BOM"
$xml = simplexml_load_string($data);
...
$xml->asXML();
If none works can try the substr
with strpos
thus:
$data = file_get_contents($url);
$data = substr($data, strpos($data, '<'));
$xml = simplexml_load_string($data);
...
$xml->asXML();
Even if you fail, it might match utf8_decode
and utf8_encode
again:
$data = file_get_contents($url);
$data = substr($data, strpos($data, '<'));
$data = utf8_decode($data);
$data = utf8_encode($data);
$xml = simplexml_load_string($data);
...
$xml->asXML();
How to resolve with text editors/processors
If you have access to these .xml
you can edit them using the Notepad++:
Or sublimetext:
ends the two xml files?
– novic
Related to Soen: https://stackoverflow.com/q/3255993/1452488
– Woss
@Virgilionovic the problem is only at the beginning of the file, so I found it irrelevant to insert all. So I’m using reticence...
– viana
These two files are created by whom?
– novic
@Virgilionovic Do you really think this is relevant to give an answer?! One for me and one for my cousin. Notepad on my pc and notepad on her pc. xD
– viana
Of course I think it’s relevant @acklay may be that the editors are in different encodings, we have to take into account the whole process, this is my view ( I don’t see anything including ) to try to help.
– novic
Saw the reply @acklay how useful it is to say how the files were created.!
– novic
@Virgilionovic But it is because it is the following, "my cousin" created an archive through a software geolocation bla bla... Then she tried to get into the system, which she was making a mistake. I asked her to send it to me, so it didn’t work. When I went to debug, appeared these special characters in front, in which the files generated on my pc does not do this.
– viana
@acklay yes of course...
– novic