I want to read a value constant from XML in PHP code.
I already tried this: $equipment->constant->name of value but is not working
<const name="IAn" value="500" um="" />
<const name="IBn" value="500" um="" />
<const name="ICn" value="500" um="" />
I want to read a value constant from XML in PHP code.
I already tried this: $equipment->constant->name of value but is not working
<const name="IAn" value="500" um="" />
<const name="IBn" value="500" um="" />
<const name="ICn" value="500" um="" />
 
    
     
    
    You can read about reading XML here: https://www.php.net/manual/en/book.simplexml.php
$xmlstr = '
    <consts>
        <const name="IAn" value="500" um="" />
        <const name="IBn" value="500" um="" />
        <const name="ICn" value="500" um="" />
    </consts>
';
In your example, you need to realize that the name attribute may not be unique. You could access ALL the elements that have the name attribute value you are looking for. Or maybe you just want the first one.
$consts = new SimpleXMLElement($xmlstr);
foreach($consts as $elem) {
    if ( $elem['name'] == 'IAn' ) {
       echo $elem['value'] . "\n";
    }
}
 
    
    There are lots of ways for this.
You can use simplexml_load_string method (if content is a string) or simplexml_load_file(if the content is in a file).
After reading the content you can loop it.
