I want to alter the class attribute of an image tag in PHP. I could do it using regex but want to use DOM / SimpleXML. The simplexml element looks like this:
$obj = simplexml_load_string($unprocessedfield);
var_dump($obj->img);
object(SimpleXMLElement)#108 (1) {
["@attributes"]=> array(6) {
["class"]=> string(33) "alignnone size-full wp-image-5499"
["title"]=> string(22) "Image: credit"
["src"]=> string(28) "/files/2010/09/laser-338.jpg"
["alt"]=> string(0) ""
["width"]=> string(3) "338"
["height"]=> string(3) "338"
}
}
I want to add to the class attribute but can't seem to access the individual elements of that array e.g. var_dump($obj->img->attributes['class'])
gives me NULL
.
thanks for any pointers.