Content Marketing

PHP: Is SimpleXML Loaded?

There are a couple plugins that I’ve built that require PHP5+ and SimpleXML. SimpleXML is a much easier and better performing method of parsing XML responses from APIs. The problem, though, is that I would get at a few emails a day or week asking me why the user couldn’t load the program and it resulted in errors.

Apparently, my notices on the plugins and on the project pages weren’t enough, so I did the right thing and added functionality to both plugins to verify the SimpleXML extension is loaded.

PHP Function to check the SimpleXML extension is loaded:

function isSimpleXMLLoaded() {
$array = array();
$array = get_loaded_extensions();
$result = false;
foreach ($array as $i => $value) {
if (strtolower($value) == "simplexml") { $result = true; }
}
return $result;
}

Now, within the functions that use SimpleXML, I can simply ensure it’s loaded before I actually try the SimpleXML call. If

if (!isSimpleXMLLoaded()) {
echo "Host your site somewhere else!";
return;
}

I know I’ve got some PHP gurus that keep an eye on my blog, let me know how I did! I’ve released minor updates to both Plugins to utilize this method.

Douglas Karr

Douglas Karr is CMO of OpenINSIGHTS and the founder of the Martech Zone. Douglas has helped dozens of successful MarTech startups, has assisted in the due diligence of over $5 bil in Martech acquisitions and investments, and continues to assist companies in implementing and automating their sales and marketing strategies. Douglas is an internationally recognized digital transformation and MarTech expert and speaker. Douglas is also a published author of a Dummie's guide and a business leadership book.

Related Articles

Back to top button
Close

Adblock Detected

Martech Zone is able to provide you this content at no cost because we monetize our site through ad revenue, affiliate links, and sponsorships. We would appreciate if you would remove your ad blocker as you view our site.