SELFPHP: Version 5.8.2 Befehlsreferenz - Tutorial – Kochbuch – Forum für PHP Einsteiger und professionelle Entwickler

SELFPHP


Professional CronJob-Service

Suche



CronJob-Service    
bei SELFPHP mit ...



 + minütlichen Aufrufen
 + eigenem Crontab Eintrag
 + unbegrenzten CronJobs
 + Statistiken
 + Beispielaufrufen
 + Control-Bereich

Führen Sie mit den CronJobs von SELFPHP zeitgesteuert Programme auf Ihrem Server aus. Weitere Infos



:: Buchempfehlung ::

Handbuch der Java-Programmierung

Handbuch der Java-Programmierung zur Buchempfehlung
 

:: Anbieterverzeichnis ::

Globale Branchen

Informieren Sie sich über ausgewählte Unternehmen im Anbieterverzeichnis von SELFPHP  

 

:: Newsletter ::

Abonnieren Sie hier den kostenlosen SELFPHP Newsletter!

Vorname: 
Name:
E-Mail:
 
 

Zurück   PHP Forum > SELFPHP > PHP Grundlagen

PHP Grundlagen Hier kann über grundlegende Probleme oder Anfängerschwierigkeiten diskutiert werden

Antwort
 
Themen-Optionen Ansicht
  #1  
Alt 27.06.2009, 00:13:33
till_ch till_ch ist offline
Anfänger
 
Registriert seit: Jun 2009
Alter: 44
Beiträge: 7
XML DOM PHP4 nach PHP5

hallots!

bin neu hier und hab gleich mal ein anliegen:

bitte gebt mir tipps wie ich folgendes script in php 5 zum laufen bring.?!?

Code:
<?php
class MenuMaker {

var $objDom;
var $arrResult;

function MenuMaker($arrResult) {
$this->arrResult = $arrResult;
$this->objDom = domxml_new_doc("1.0");
$ndRoot =
$this->objDom->append_child($this->objDom->create_element("menu"));
foreach($this->arrResult AS $arrTopRow) {
if($arrTopRow["parent_id"] == 0) {
$this->handleMenuItem($arrTopRow,$ndRoot);
}
}
}

function handleMenuItem($arrRow,$nd) {

// display the thing...
$ndItem = $this->printMenuItem($arrRow,$nd);

//{{{ create a temporrary stack of immediate children
$arrTmp = array();
foreach($this->arrResult AS $arrSubRow) {
if($arrRow["id"] == $arrSubRow["parent_id"]) {
$arrTmp[] = $arrSubRow;
}
}
//}}}

// execute the immdiate children in a row (ordered)
foreach($arrTmp AS $arrSubRow){
$this->handleMenuItem($arrSubRow,$ndItem);
}
}

function printMenuItem($arrRow,$nd) {
$ndItem = $nd->append_child($this->objDom->create_element("item"));
foreach($arrRow AS $key=>$val) {
$ndTitle =
$ndItem->append_child($this->objDom->create_element($key));
$ndTitle->set_content($val);
}
return $ndItem;
}

function getXml() {
return $this->objDom->dump_mem(true);
}
}

$arrFakeResult = array();
$arrFakeResult[] =
array("id"=>1,"parent_id"=>0,"title"=>"project","h ref"=>"project/");
$arrFakeResult[] =
array("id"=>2,"parent_id"=>0,"title"=>"faq","href" =>"faq/");
$arrFakeResult[] =
array("id"=>3,"parent_id"=>0,"title"=>"contact","h ref"=>"contact.php");
$arrFakeResult[] =
array("id"=>4,"parent_id"=>1,"title"=>"aims","href "=>"project/aims/");
$arrFakeResult[] =
array("id"=>5,"parent_id"=>1,"title"=>"objectives" ,"href"=>"project/obj/");
$arrFakeResult[] =
array("id"=>6,"parent_id"=>4,"title"=>"easy","href "=>"project/aims/easy.php");
$arrFakeResult[] =
array("id"=>7,"parent_id"=>4,"title"=>"scalable"," href"=>"project/aims/sclable.php");
$arrFakeResult[] =
array("id"=>8,"parent_id"=>4,"title"=>"robust","hr ef"=>"project/aims/robust.php");
$arrFakeResult[] = array("id"=>9,"parent_id"=>5,"title"=>"object
oriented","href"=>"project/obj/oo.php");
$arrFakeResult[] =
array("id"=>10,"parent_id"=>5,"title"=>"xml","href "=>"project/obj/xml.php");

$objMM = new MenuMaker($arrFakeResult);
header("Content-Type: text/xml");
echo $objMM->getXml();

?>
danke.
till.


**edit**

habs selbst hinbekommen.
eine nacht php dom.
falls wers brauchen kann:


Code:
<?php

class MenuMaker {

var $objDom;
var $arrResult;

function MenuMaker($arrResult) {
$this->arrResult = $arrResult;
$this->objDom = new DOMDocument();

   $this->objDom->preserveWhiteSpace = false;


$ndRoot =
$this->objDom->appendChild($this->objDom->createElement("menu"));
foreach($this->arrResult as $arrTopRow) {
if($arrTopRow["parent"] == 0) {
$this->handleMenuItem($arrTopRow,$ndRoot);
}
}
}

function handleMenuItem($arrRow,$nd) {

// display the thing...
$ndItem = $this->printMenuItem($arrRow,$nd);

//{{{ create a temporrary stack of immediate children
$arrTmp = array();
foreach($this->arrResult as $arrSubRow) {

if($arrRow["id"] == $arrSubRow["parent"]) {
$arrTmp[] = $arrSubRow;
}
}
//}}}

// execute the immdiate children in a row (ordered)
foreach($arrTmp as $arrSubRow){
$this->handleMenuItem($arrSubRow,$ndItem);
}
}


function printMenuItem($arrRow,$nd) {
$ndTitle = $nd->appendChild($this->objDom->createElement("item"));
foreach($arrRow as $key=>$val) {

$ndTitle->setAttribute($key,$val);
}
return $ndTitle;
}



function getXml() {
return $this->objDom->saveXML();
}
}

require_once('../array_from_db.php');

$objMM = new MenuMaker($arrFakeResult);

echo $objMM->getXml();

?>

und der array schaut so aus:


Code:
Array
(
    [0] => Array
        (
            [0] => HOME
            [id] => 1
            [parent] => 0
            [title] => HOME
            [display] => 1
            [artist_id] => random
        )

    [1] => Array
        (
            [0] => MALEREI
            [id] => 2
            [parent] => 0
            [title] => MALEREI
        )

    [2] => Array
        (
            [0] => REISETAGEBUCH
            [id] => 3
            [parent] => 0
            [title] => REISETAGEBUCH
        )

    [3] => Array
        (
            [0] => FOTOGRAFIE
            [id] => 4
            [parent] => 0
            [title] => FOTOGRAFIE
        )

    [4] => Array
        (
            [0] => SKULPTUR
            [id] => 5
            [parent] => 0
            [title] => SKULPTUR
        )

    [5] => Array
        (
            [0] => 19. JHDT
            [id] => 7
            [parent] => 2
            [title] => 19. JHDT
        )

    [6] => Array
        (
            [0] => 20. JHDT
            [id] => 8
            [parent] => 2
            [title] => 20. JHDT
        )

    [7] => Array
        (
            [0] => ITALIEN
            [id] => 9
            [parent] => 3
            [title] => ITALIEN
        )

    [8] => Array
        (
            [0] => USA
            [id] => 10
            [parent] => 3
            [title] => USA
        )

    [9] => Array
        (
            [0] => EXPERIMENTS
            [id] => 11
            [parent] => 4
            [title] => EXPERIMENTS
        )

    [10] => Array
        (
            [0] => ALUGUSS
            [id] => 12
            [parent] => 5
            [title] => ALUGUSS
        )

    [11] => Array
        (
            [0] => Claude Monet
            [id] => 13
            [parent] => 7
            [title] => Claude Monet
            [text] => 
            [display] => true
            [artist_id] => 191
        )

    [12] => Array
        (
            [0] =>   Renoir
            [id] => 14
            [parent] => 7
            [title] =>   Renoir
            [text] => 
            [display] => true
            [artist_id] => 180
        )

    [13] => Array
        (
            [0] => Gottfried Helnwein
            [id] => 15
            [parent] => 8
            [title] => Gottfried Helnwein
            [text] => 
            [display] => true
            [artist_id] => 189
        )

    [14] => Array
        (
            [0] => Edward Hopper
            [id] => 16
            [parent] => 8
            [title] => Edward Hopper
            [text] => 
            [display] => true
            [artist_id] => 190
        )

    [15] => Array
        (
            [0] => Pablo Picasso
            [id] => 17
            [parent] => 8
            [title] => Pablo Picasso
            [text] => 
            [display] => true
            [artist_id] => 188
        )

    [16] => Array
        (
            [0] => Otto Dix
            [id] => 18
            [parent] => 8
            [title] => Otto Dix
            [text] => 
            [display] => true
            [artist_id] => 187
        )

    [17] => Array
        (
            [0] => Venedig  
            [id] => 19
            [parent] => 9
            [title] => Venedig  
            [text] => 
            [display] => true
            [artist_id] => 184
        )

    [18] => Array
        (
            [0] => Florenz  
            [id] => 20
            [parent] => 9
            [title] => Florenz  
            [text] => 
            [display] => true
            [artist_id] => 182
        )

    [19] => Array
        (
            [0] => Rom  
            [id] => 21
            [parent] => 9
            [title] => Rom  
            [text] => 
            [display] => true
            [artist_id] => 183
        )

    [20] => Array
        (
            [0] => Philadelphia  
            [id] => 22
            [parent] => 10
            [title] => Philadelphia  
            [text] => 
            [display] => true
            [artist_id] => 186
        )

    [21] => Array
        (
            [0] => New York
            [id] => 23
            [parent] => 10
            [title] => New York
            [text] => 
            [display] => true
            [artist_id] => 185
        )

    [22] => Array
        (
            [0] => Sperrmüll  
            [id] => 24
            [parent] => 11
            [title] => Sperrmüll  
            [text] => 
            [display] => true
            [artist_id] => 179
        )

    [23] => Array
        (
            [0] => Die drei Schwestern II  
            [id] => 25
            [parent] => 12
            [title] => Die drei Schwestern II  
            [text] => 
            [display] => true
            [artist_id] => 181
        )

)

Geändert von till_ch (27.06.2009 um 20:17:57 Uhr)
Mit Zitat antworten
Antwort


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 
Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind aus.
[IMG] Code ist aus.
HTML-Code ist aus.

Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
PHP4 zu PHP5 Problem maiskolben PHP für Fortgeschrittene und Experten 12 08.04.2009 13:05:37
Zeichensatzproblem beim Wechsel von php4 zu php5 sputnik72 PHP Grundlagen 2 01.04.2008 19:32:57
HTML-Mails bei Wechsel PHP4 auf PHP5 Willow PHP Grundlagen 40 14.11.2007 21:17:25
php4 - php5 functionsaufruf! swishy PHP für Fortgeschrittene und Experten 2 24.08.2005 00:57:37
PHP5 - Macht php4 noch sinn? xStream Off Topic Area 6 18.07.2003 11:17:27


Alle Zeitangaben in WEZ +2. Es ist jetzt 16:00:38 Uhr.


Powered by vBulletin® Version 3.8.3 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.


© 2001-2024 E-Mail SELFPHP OHG, info@selfphp.deImpressumKontakt