/** * valid string to xml support namespace * @param $xml * @param array $namespaces * @return string */ public static function string2xml_withNS($xml, $namespaces = array()) { $root = '<rss '; $attsNS = HW_WXR_Parser_SimpleXML::valid_namespaces(); if (is_array($namespaces) && count($namespaces)) { $attsNS = array_merge($attsNS, $namespaces); } foreach ($attsNS as $ns => $uri) { $root .= 'xmlns:' . $ns . '="' . $uri . '" '; } $root .= '>'; if (is_string($root) && HW_XML::string_is_xml_format($xml)) { $root .= $xml; } $root .= '</rss>'; $doc = new DOMDocument(HW_Export::XML_VERSION, HW_Export::XML_ENCODING); $doc->loadXML($root); return $doc->documentElement; }
/** * @param $string * @param $tag * @Param $xml_object return xml in object without string * @return mixed|string */ function get_tag($string, $tag, $xml_object = false) { preg_match("|<{$tag}.*?>(.*?)</{$tag}>|is", $string, $return); if (isset($return[1])) { if (substr($return[1], 0, 9) == '<![CDATA[') { if (strpos($return[1], ']]]]><![CDATA[>') !== false) { preg_match_all('|<!\\[CDATA\\[(.*?)\\]\\]>|s', $return[1], $matches); $return = ''; foreach ($matches[1] as $match) { $return .= $match; } } else { $return = preg_replace('|^<!\\[CDATA\\[(.*)\\]\\]>$|s', '$1', $return[1]); } } else { $return = $return[1]; } } else { $return = ''; } if ($xml_object && trim($return) && HW_XML::string_is_xml_format($return)) { return HWIE_Param::string2xml_withNS($return); } return $return; }