Reputation: 47
This code pulls the name of a shipping option from Canada Post's server. I need to somehow specify that if it comes back as "Expedited" it should say "Canada Post" instead. Is that possible?
$name = substr(
$resultXML,
strpos($resultXML, "<name>") + strlen("<name>"),
strpos($resultXML, "</name>") - strlen("<name>") - strpos($resultXML, "<name>")
);
Upvotes: 0
Views: 37
Reputation: 2497
You need to use simple xml parser which is built into php
// make it more error friendly
$saved = libxml_use_internal_errors(true);
//load the xml as object
$xml = simplexml_load_string($inputString);
if ($xml === false) {
foreach (libxml_get_errors() as $error) {
echo $error->message, "\n";
}
libxml_use_internal_errors($saved);
return;
}
libxml_use_internal_errors($saved);
echo $xml->asXML(); //you can see the XML here
get the name as per object position like $xml->obj1->name
etc
Upvotes: 0
Reputation: 73041
You can use a simple if
statement:
if ($name === 'Expedited') {
$name = 'Canada Post';
}
Upvotes: 1