The code below will work fine if the "name" element in the XML file below does not have a leading space. In an XPath ss expression, is there a way to crop the leading space of an XML element? Or is there any other way to deal with such a problem with a space? Thank you
$xmldoc = simplexml_load_file("products.xml");
$query = $xmldoc->xpath('/products/product[starts-with(name, "Desk")]');
foreach($query as $Products) {
echo $Products->name . " ";
echo $Products->price . "<br>";
}
<products>
<product type="Electronics">
<name> Desktop</name>
<price>499.99</price>
<store>Best Buy</store>
</product>
source
share