streetparade
streetparade

Reputation: 32878

Invalid XML Replace Content in PHP

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

Upvotes: 1

Views: 469

Answers (4)

Jan Goyvaerts
Jan Goyvaerts

Reputation: 21999

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);

Upvotes: 2

Matteo Riva
Matteo Riva

Reputation: 25060

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

Upvotes: 0

nickf
nickf

Reputation: 546035

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.

Upvotes: 0

nickf
nickf

Reputation: 546035

error_reporting(0);

Upvotes: 0

Related Questions