Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Emulare mysql_fetch_object parsing a xml file

    Ciao.
    Secondo voi è un metodo valido
    per emulare mysql_fetch_object:
    Codice PHP:
    <?php
    class Builder{
        public function 
    __construct(){}
          public function 
    __get($nm){
               return 
    $this->{$nm};
           }
        public function 
    __set($nm$val){
            
             
    $this->{$nm} = $val;
        }
    }
    class 
    Example{
        public 
    $items = array(array("id" => 1"title" => "One""content" => "Bla bla one"),array("id" => 1"title" => "Two""content" => "Bla bla two"));
        public 
    $b=array();
        function 
    setObjects() {
        
    //Quando recupero il nome del tag e il suo valore facendo il parsing di un xml file
        //farei una cosa del genere 
            
    foreach($this->items as $value){
                
    $builder= new Builder();
                    foreach(
    $value as $key => $v){
                        
    $builder->{$key}= $v;
        
                    }
                
    $this->b[]=$builder;
                unset(
    $builder);
            }
        }
        function 
    fetchObject(){
            if(
    $obj=array_shift($this->b)){
                return 
    $obj;
            }
            else{
                return 
    false;
            }
        }
    }
    $class = new Example();
    $class->setObjects();
    while(
    $obj $class->fetchObject()){
        echo 
    $obj->id."-".$obj->title."-".$obj->content."
    "
    ;
    }
    ?>
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  2. #2
    UP
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.