$xml - string with SOAP request/response * @return $format_xml - array with tags */ function format_xml($xml) { $format_xml = array(); for ($i = 0; $i < strlen($xml); $i++) { $start_pos = stripos($xml, '<'); $stop_pos = stripos($xml, '>'); $tag = substr($xml, $start_pos+1, $stop_pos-$start_pos-1); $xml = substr($xml, $stop_pos+1); /* search for ending tag in $xml remained */ $end_tag = strstr($xml, '/' . $tag); if (strlen($end_tag) > 0) { $end_tag_pos = strlen($xml) - strlen($end_tag); if ((stripos($xml, '<')+1) == $end_tag_pos) { $value = substr($xml, 0, $end_tag_pos); $tag_name = $tag; $tag = $tag_name . '>' .$value. '/' .$tag_name; $xml = substr($end_tag, strlen($tag_name)+2); } } $format_xml[] = $tag; } $tags_no = count($format_xml); if ($tags_no > 0) { $format_xml[0] = '<'.$format_xml[0]; $format_xml[$tags_no-1] = $format_xml[$tags_no-1].'>'; } if (!empty($format_xml[1])) { $envelope = explode(' ', $format_xml[1]); for ($i = 1; $i < count($envelope)-1; $i++) { $envelope[$i] = $envelope[$i]."\n"; } $format_xml[1] = implode(' ', $envelope); return $format_xml; } else { return FALSE; } } /** * Formats a hash of languages in format 'code' => 'name' * @param $languages - object with languages information * @return $format_lang - array of languages */ function format_languages($languages) { $format_lang = array(); if (is_array($languages) && !empty($languages)) { foreach ($languages as $key => $val) { $lang = get_object_vars($val); $format_lang[$lang['code']] = $lang['name']; } } return $format_lang; } /** * Splits a faultstring to fit to a fix area * @param $xml_array - array with xml tags * @param $width - fix area size * @return $xml_array - formated array with XML tags */ function split_faultstring($xml_array, $width = '') { if (!empty($xml_array)) { foreach ($xml_array as $key => $val) { if (is_numeric(strpos($val, 'faultstring>')) || is_numeric(strpos($val, 'message>'))) { $length = 20; if (!empty($width)) { $length = $width/7; } $val = wordwrap($val, $length, "\n"); $xml_array[$key] = $val; } } return $xml_array; } return FALSE; } /** * Gets the location of the local schemes, based on the location of a php script * @param string $script_location - the location of the script * @return string $location - the location of the local schemes */ function get_local_schemes_location($script_location) { $lastslashpos = strrpos($script_location, "/"); $location = substr($script_location, 0, $lastslashpos); $secondlastpos = strrpos($location, "/"); $location = substr($location, 0, $secondlastpos + 1); return $location; }