tags:

views:

92

answers:

4

I have a invalid XML like this

Warning: count() [function.count]: Node no longer exists in /var/bla/test.php
<?xml version="1.0" encoding="ISO-8859-1"?>
<nodes>
<some>test</some>
</nodes>

Now i need a regex which would replace the Warning: count() [function.count]: Node no longer exists in /var/bla/test.php with "" how can i do that?

The above xml is is not generated on my localmachine, its a api call which returned a invalid xml

A: 

error_reporting(0);

nickf
Its not on my local machine its from a api
streetparade
A: 

This blog post might have the answer.

The short story is to cast to a string if you want to use the value of an attribute or node.

nickf
A: 

Sticking to your question, just remove the first line of that file.

kemp
+1  A: 

Assuming you have to use a regular expression for some reason, this line of PHP removes everything from the start of the string until the first occurrence of <?xml:

$output = preg_replace('/\A.*?<\?xml/s', '<?xml', $input);
Jan Goyvaerts