Skip to content

Instantly share code, notes, and snippets.

@ginsengs
Created June 30, 2018 11:53
Show Gist options
  • Save ginsengs/9b666987159bd23af01b7249fa778d05 to your computer and use it in GitHub Desktop.
Save ginsengs/9b666987159bd23af01b7249fa778d05 to your computer and use it in GitHub Desktop.
<?php
$mapReplaces = [
'ORDER_ID' => 'MARGO'
];
$text
= '<?xml version="1.0" encoding="utf-8"?>
<ShipOrderDocument xmlns="http://schemas.quietlogistics.com/V2/ShipmentOrder.xsd" >
<ClientID>SKITHEEAST</ClientID>
<BusinessUnit>SKITHEEAST</BusinessUnit>
<OrderHeader OrderNumber="{ORDER_ID}" OrderType="SO" OrderDate="{ORDER_DATE}"
ShipDate="{ORDER_DATE}">
<Comments>{NOTE}</Comments>
<ShipMode Carrier="{SHIPPING_TITLE}" ServiceLevel="[Order???]"/>';
$result = preg_replace_callback('/{(.*?)}/si', function ($match) use ($mapReplaces) {
if (isset($mapReplaces[$match[1]])) {
return $mapReplaces[$match[1]];
}
}, $text);
dd($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment