I am using simplexml to load an API URL in the form of an XML through php. In the ProductDescription element it contains html that I would like to append onto in the warranty section.
I would like to add <li>Valid in US</li> in the ProductDescription element before the LAST </ul> tag:
<xmldata>
<Products>
<ProductCode>ACODE</ProductCode>
<ProductID>1234</ProductID>
<ProductName>PRODUCTTITLE</ProductName>
<ProductDescription>
<h1>Stuff</h1><p>description</p><hr /><strong>Features & Benefits</strong>
<ul><li>feat</li><li>feat</li><li>feat</li></ul><hr /><strong>Specifications</strong><ul><li>spec</li><li>spec</li><li>spec</li></ul> <hr /><strong>Warranty Information for a certain product</strong>
<ul><li>3 Years Parts</li><li>3 Years Labor</li></ul><div> <a href="/ahref" target="_blank">See more products from MFG </a></div>
</ProductDescription>
<ProductManufacturer>MFG</ProductManufacturer>
</Products>
</xmldata>
Now all I can do is get the bare code out of the ProductDescription, I need to know of a way to add that list tag to end of the last ul tag before posting or displaying. Here is my partial php:
foreach( $xml as $NEW_XML )
{
$code = $NEW_XML->ProductCode;
$name = $NEW_XML->ProductName;
$desc = $NEW_XML->ProductDescription;
$mfg = $NEW_XML->ProductManufacturer;
echo "<textarea rows='13' cols='64' name='DESC' />" . $desc. "</textarea>"; }
I am hoping I dont have to use REGex as it could be a pain (unless someone knows of a way). My inital thoughts would be to put it into a <textarea> and simply posting it back to an xml, but if there is a way to get to save as an .xml directly that would be more effiecient.
If the number of
uls is known, you can add the information like this:This assumes that
$NEW_XMLis pointing at theProducts-Element. To always get the lastulyou have to count them first:Then you can just output or save
$xml->asXML().Update:
Here is the complete code I used, updated according to my assumption from my last comment, maybe this helps: