Skip to content

Instantly share code, notes, and snippets.

@kobus1998
Created October 16, 2018 12:41
Show Gist options
  • Save kobus1998/0f07f6d313a1b34963db124682cbcb1b to your computer and use it in GitHub Desktop.
Save kobus1998/0f07f6d313a1b34963db124682cbcb1b to your computer and use it in GitHub Desktop.
Strip XML namespaces
<?php
// namespaces can be a pain in the ass, well NO LONGER!
function stripNamespaces($xml)
{
return preg_replace([
"/(\<(\w*|\-)*\:)/", // start node namespaces
"/(\<(\/{0,1})(\w*|\-)*\:)/", // end node namespaces
"/(\s\w*\:)/" // attribute namespaces
], [
"<",
"</",
" "
], $xml);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment