A call like addAttribute("attrname", "") results in "PHP Warning: SimpleXMLElement::addAttribute(): Attribute name and value are required". In addition to the warning, the attribute is discarded.
<?php
$xml = new SimpleXmlElement("<img></img>");
$xml->addAttribute("src", "foo");
$xml->addAttribute("alt", "");
echo $xml->asXML()."\n";
?>
<?xml version="1.0"?>
<img src="foo" alt=""/>
PHP Warning: SimpleXMLElement::addAttribute(): Attribute name and value are required in [...]/test.php on line 4
<?xml version="1.0"?>
<img src="foo"/>
this problem exists in PHP 5.2.1, but in PHP5.3.5 it works as I expect, but I can't change my php version(for some reason). Is there any way to solve this?
can you try by changing below line
$xml = new SimpleXmlElement("<img>");
and also you can try with below also
$xml = new DOMDocument('1.0', 'iso-8859-1');
$doc = $xml->createElement('document');
$doc = $xml->appendChild($doc);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With