Esempio n. 1
0
function simplexml2array($xml)
{
    if (get_class($xml) == 'SimpleXMLElement') {
        $attributes = $xml->attributes();
        foreach ($attributes as $k => $v) {
            if ($v) {
                $a[$k] = (string) trim(iconv('ISO-8859-1', 'UTF-8', $v));
            }
        }
        # Added the "trim" to this line, as there was a lot of crap being carried along with the XML.
        # Currently unsupported characters are being displayed. These need to be changed into their correct characters.
        $x = trim($xml);
        $xml = get_object_vars($xml);
    }
    if (is_array($xml)) {
        if (count($xml) == 0) {
            return (string) $x;
        }
        // for CDATA
        foreach ($xml as $key => $value) {
            $r[$key] = simplexml2array($value);
        }
        if (isset($a)) {
            $r['@'] = $a;
        }
        // Attributes
        return $r;
    }
    return (string) $xml;
}
Esempio n. 2
0
/**
 * Grundfunktionen für myBooks
 *
 * In dieser Datei werden Funktionen gespeichert die für verscheidenste Seitenm benutzt werden
 *
 * PHP Version nur mit Version 5 getestet
 *
 * Lizens: Diese Datei wurde unter der GNU Public License lizensiert, diese
 * liegt in der Datei COPYING im Hauptverzeichnis wenn sie die Datei nicht
 * mit erhalten haben, ist sie unter http://www.gnu.org/copyleft/gpl.html
 * zu finden.
 *
 * @package    myBooks
 * @author     Fabian Mruck <*****@*****.**>
 * @copyright  2006 Fabian Mruck
 * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
 * @version    SVN: $Id$
 */
function simplexml2array($xml)
{
    if (get_class($xml) == 'SimpleXMLElement') {
        $attributes = $xml->attributes();
        foreach ($attributes as $k => $v) {
            if ($v) {
                $a[$k] = (string) $v;
            }
        }
        $x = $xml;
        $xml = get_object_vars($xml);
    }
    if (is_array($xml)) {
        if (count($xml) == 0) {
            return (string) $x;
        }
        // for CDATA
        foreach ($xml as $key => $value) {
            $r[$key] = simplexml2array($value);
            // original line instead of the following if statement:
            //$r[$key] = simplexml2ISOarray($value);
            if (!is_array($r[$key])) {
                $r[$key] = utf8_decode($r[$key]);
            }
        }
        if (isset($a)) {
            $r['@'] = $a;
        }
        // Attributes
        return $r;
    }
    return (string) $xml;
}
Esempio n. 3
0
function SimpleXML2Array($xml)
{
    if (get_class($xml) == 'SimpleXMLElement') {
        $attributes = $xml->attributes();
        foreach ($attributes as $k => $v) {
            if ($v) {
                $a[$k] = (string) $v;
            }
        }
        $x = $xml;
        $xml = get_object_vars($xml);
    }
    if (is_array($xml)) {
        if (count($xml) == 0) {
            return (string) $x;
        }
        // for CDATA
        foreach ($xml as $key => $value) {
            $r[$key] = simplexml2array($value);
        }
        if (isset($a)) {
            $r['@'] = $a;
        }
        // Attributes
        return $r;
    }
    return (string) $xml;
}
Esempio n. 4
0
        break;
}
$ISBN_lang = "de";
$url = "http://webservices.amazon.";
$url .= $ISBN_lang;
$url .= "/onca/xml";
$url .= "?Service=AWSECommerceService";
$url .= "&SubscriptionId=";
$url .= AMAZONID;
$url .= "&Operation=ItemLookup";
$url .= "&ItemId=";
$url .= $ISBN;
$url .= "&MerchantId=All";
$url .= "&ResponseGroup=Medium,ItemAttributes,EditorialReview,Reviews";
$xml = simplexml_load_file($url);
$xml1 = simplexml2array($xml);
/*
echo '<a href="'.$xml1[Items][Item][DetailPageURL].'">Buch bei Amazon kaufen</a><br />';
if ($xml1[Items][Item][LargeImage][URL]){
    if (!file_exists("/kunden/115002_90607/buch/mybooks/images/large/$ISBN.jpg")) {
        copy($xml1[Items][Item][LargeImage][URL], "/kunden/115002_90607/buch/mybooks/images/large/$ISBN.jpg");
    }
    echo '<img src="http://book.fabi.ws/mybooks/images/large/'.$ISBN.'.jpg" alt="'.$ISBN.'" />';
}
if ($xml1[Items][Item][MediumImage][URL]){
    if (!file_exists("/kunden/115002_90607/buch/mybooks/images/medium/$ISBN.jpg")) {
        copy($xml1[Items][Item][MediumImage][URL], "/kunden/115002_90607/buch/mybooks/images/medium/$ISBN.jpg");
    }
    echo '<img src="http://book.fabi.ws/mybooks/images/medium/'.$ISBN.'.jpg" alt="'.$ISBN.'" />';
}
if ($xml1[Items][Item][SmallImage][URL]){
Esempio n. 5
0
/**
 * 将xml转成array,方法1
 *
 * $param object simplexml object.
 */
function cy_simplexml2array($obj)
{
    if (empty($obj)) {
        return '';
    }
    $data = array();
    foreach ($obj as $key => $val) {
        if (is_array($val) || is_object($val)) {
            $data[$key] = simplexml2array((array) $val);
        } else {
            $data[$key] = (string) $val;
        }
    }
    return $data;
}
Esempio n. 6
0
     $recCat->code = $category["@attributes"]["code"];
     $recCat->name_est = $category["@attributes"]["default_name"];
     $recCat->master = $category["@attributes"]["master"];
     $recCat->masters = $category["@attributes"]["masters"];
     $arrCategories[$category["@attributes"]["code"]] = $recCat;
     unset($recCat);
 }
 $xml = get_url_content("/ocra_4room/transport/xmlcore.asp?get=1&what=item", "directo5.gate.ee", 443, "ssl://");
 $dom = new domDocument();
 $dom->loadXML($xml);
 if (!$dom) {
     echo 'Error while parsing the document';
     exit;
 }
 $s = simplexml_import_dom($dom);
 $tmp_arr = simplexml2array($s);
 //printout($tmp_arr);
 //exit;
 foreach ($tmp_arr["items"]["item"] as $product) {
     $recProd->code = $product["@attributes"]["code"];
     $recProd->name_est = $product["@attributes"]["default_name"];
     $recProd->price = round($product["@attributes"]["retail_price"]);
     $recProd->special_price1 = $product["@attributes"]["special_price1"];
     $recProd->special_price2 = $product["@attributes"]["special_price2"];
     $recProd->category_name_id = $product["@attributes"]["class"];
     $recProd->on_purchase = $product["@attributes"]["on_purchase"];
     if (is_array($product["data"])) {
         foreach ($product["data"] as $parameters) {
             if (is_array($parameters["@attributes"])) {
                 if ($parameters["@attributes"]["code"] == "ART_LANG") {
                     $recProd->{"name_" . strtolower($parameters["@attributes"]["param"])} = $parameters["@attributes"]["content"];
Esempio n. 7
0
 function getManifests($path)
 {
     global $sd_files;
     $sd_files = array();
     scan_directory_recursively($path, 'xml', 2);
     foreach ($sd_files as $file) {
         $path = $file['file'];
         if (basename($path) == 'config.xml') {
             continue;
         }
         // Ignore config files
         try {
             $contents = file_get_contents($path);
             $xml = new SimpleXMLElement($contents);
             $name = strtolower($xml->getName());
             if ($name == 'install' || $name == 'mosinstall') {
                 $xml = simplexml2array($xml);
                 $jid = self::getJidFromXML($xml, "{$path}:{$name}");
                 $version = $xml['version'];
                 $this->versions[$jid] = $version;
             }
         } catch (Exception $e) {
             // can't read it, do nothing
         }
     }
 }
Esempio n. 8
0
/**
 * Turns a SimpleXMLElement into an array
 *
 * @param SimpleXMLelem $xml
 * @return array 
 */
function simplexml2array($xml)
{
    if (is_object($xml) && get_class($xml) == 'SimpleXMLElement') {
        $attributes = $xml->attributes();
        foreach ($attributes as $k => $v) {
            $a[$k] = (string) $v;
        }
        $x = $xml;
        $xml = get_object_vars($xml);
    }
    if (is_array($xml)) {
        if (count($xml) == 0) {
            return (string) $x;
        }
        $r = array();
        foreach ($xml as $key => $value) {
            $r[$key] = simplexml2array($value);
        }
        // Ignore attributes
        if (isset($a)) {
            $r['@attributes'] = $a;
        }
        return $r;
    }
    return (string) $xml;
}
Esempio n. 9
0
 foreach ($url_list as $key => $url) {
     $data = read_xml_file($host, $port, $url);
     if ($data) {
         $dom[$key] = new domDocument();
         $dom[$key]->loadXML($data);
         if (!$dom[$key]) {
             echo '<span style="font-weight: bold; color: red;">Tekkis viga XML\'i parsimisel. [' . $key . ']</span>';
             exit;
         }
     } else {
         echo '<span style="font-weight: bold; color: red;">Ühenduse loomine ebaõnnestus. Info vastuvõtmine ebaõnnestus. [' . $key . ']</span>';
         exit;
     }
 }
 foreach ($dom as $key => $d) {
     $imports[$key] = @simplexml2array(simplexml_import_dom($d));
 }
 // receiving IDs about all variables in array
 $id = get_variables_ids();
 if (!$id) {
     echo '<span style="font-weight: bold; color: red;">Tekkis viga muutujate informatsiooni leidmisel.</span>';
     exit;
 }
 $sql_countries = 'INSERT INTO `newcms2_catalog_variable_selection` (`ID`,`parentID`,`name_eng`,`name_est`) VALUES ';
 $sql_sections = 'INSERT INTO `newcms2_catalog_category` (`ID`,`parentID`,`title_eng`,`title_est`,`name_eng`,`name_est`,`title_rus`,`name_rus`,`content_eng`,`content_est`) VALUES ';
 $sql_cinemas = 'INSERT INTO `newcms2_catalog_product_cinemas` (`id`,`title_eng`,`title_est`) VALUES ';
 $sql_films = 'INSERT INTO `newcms2_catalog_product` (`ID`,`parentID`,`title_est`,`title_eng`,`title_rus`,`name`,`title_visible`,`last_modified`,`modifier`) VALUES ';
 $sql_films_variables = 'INSERT INTO `newcms2_catalog_product_value` (`productID`,`variableID`,`value_est`,`value_eng`,`value_boolean`,`value_id`) VALUES ';
 $sql_films_categoris = 'INSERT INTO `newcms2_catalog_product_category` (`productID`,`categoryID`) VALUES ';
 $sql_directors = 'INSERT INTO `newcms2_catalog_product_directors` (`id`,`name`,`surname`,`filmography_eng`,`filmography_est`,`bio_eng`,`bio_est`,`statement_eng`,`statement_est`) VALUES ';
 $sql_screenings = 'INSERT INTO `newcms2_catalog_product_screenings` (`id`,`film_id`, `date`, `time`, `cinema_id`, `ID_AKCE`, `buylink`, `subtitles`, `info_est`, `info_eng`, `code`) VALUES ';