Skip to content

Instantly share code, notes, and snippets.

@nixonmedia
Last active April 11, 2018 15:59
Show Gist options
  • Save nixonmedia/6e2e68c3afd131612534fae3396d62f9 to your computer and use it in GitHub Desktop.
Save nixonmedia/6e2e68c3afd131612534fae3396d62f9 to your computer and use it in GitHub Desktop.
foreach ($entries as $entry){
$xmlstr = <<<XML
<?xml version='1.0' encoding='UTF-8'?>
<complaints></complaints>
XML;
$complaints = new SimpleXMLElement($xmlstr);
$complaint= $complaints->addChild('Complaint');
$complaint->addChild('EntryID', $entryID);
$complaint->addChild('ComplaintType', 'Consumer');
$complaint->addChild('CreatedOn',$date_dash);
$complaint->addChild('Address1',$address);
$complaint->addChild('Address2',$address2);
$complaint->addChild('Age',$age);
$complaint->addChild('AgenciesContacted',htmlspecialchars($agencies_contacted, ENT_XML1 | ENT_QUOTES, 'UTF-8'));
$complaint->addChild('AnyOtherAgency',$contacted_other_agencies);
$complaint->addChild('BusinessAddress',$business_address);
$complaint->addChild('BusinessAddress2',$business_address_2);
$complaint->addChild('BusinessCity',$business_city);
$complaint->addChild('BusinessContact',htmlspecialchars($business_contact, ENT_XML1 | ENT_QUOTES, 'UTF-8'));
$complaint->addChild('BusinessName',htmlspecialchars($business_name, ENT_XML1 | ENT_QUOTES, 'UTF-8'));
//outputs
<?xml version="1.0" encoding="UTF-8"?>
<complaints>
<Complaint>
<EntryID>779</EntryID>
<ComplaintType>Consumer</ComplaintType>
<CreatedOn>2018-04-11</CreatedOn>
<Address1>123 Hill Street, Suite 100</Address1>
<Address2>Suite 100</Address2>
<Age>55</Age>
<AgenciesContacted>IRS, FBI</AgenciesContacted>
<AnyOtherAgency>Yes</AnyOtherAgency>
<BusinessAddress>800 Street Road</BusinessAddress>
<BusinessAddress2>Suite 99</BusinessAddress2>
<BusinessCity>Lancaster</BusinessCity>
<BusinessContact>Scott Wagner</BusinessContact>
<BusinessName>Scotts Lawn Care</BusinessName>
<BusinessPhone>9999999999</BusinessPhone>
<BusinessState>PA</BusinessState>
<BusinessZip>17562</BusinessZip>
<City1>Harrisburg</City1>
<County>Clinton</County>
<DayTimePhoneNumber>8888888888</DayTimePhoneNumber>
<AlternatePhoneNumber>4444444444</AlternatePhoneNumber>
<Email>[email protected]</Email>
<State>PA</State>
<Zip>17111</Zip>
<IsVetaran>Yes</IsVetaran>
<ComplaintSummary>They put seed on my lawn and killed my grass</ComplaintSummary>
</Complaint>
</complaints>
<?xml version="1.0" encoding="UTF-8"?>
<complaints>
$complaint->addChild('BusinessPhone',$business_phone);
$complaint->addChild('BusinessState',$business_state);
$complaint->addChild('BusinessZip',$business_zip);
$complaint->addChild('City1',$city);
$complaint->addChild('County',$county);
$complaint->addChild('DayTimePhoneNumber',$phone);
$complaint->addChild('AlternatePhoneNumber',$alt_phone);
$complaint->addChild('Email',$email);
$complaint->addChild('State',$state);
$complaint->addChild('Zip',$zip);
$complaint->addChild('IsVetaran',$vet);
$complaint->addChild('ComplaintSummary',htmlspecialchars($complaint_summary, ENT_XML1 | ENT_QUOTES, 'UTF-8'));
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($complaints->asXML());
echo $dom->saveXML();
}//for each
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment