Class Html

Mr. PHP

Utente Attivo
31 Gen 2013
141
0
0
Ho questa classe Html il problema e che non funziona come dovrebbe, qualcuno sa come mai ???
PHP:
class Html {
	
	private $tag = '', $open_tag = '', $close_tag = '';
	
	public function tag( $tag, $value, $attr = '' ){

		if( is_object( $value ) ){
			
			$this->open_tag .= '<'.$tag.$this->attr( $attr ).'>';
			
			$this->close_tag .= '</'.$tag.'>';
			
		}else{
			
			if( $this->open_tag != '' ){
				
				$this->tag .= $this->open_tag;
				
				$this->open_tag = '';
				
			}
			
			$this->tag .= '<'.$tag.$this->attr( $attr ).'>'.$this->value( $value ).'</'.$tag.'>';
											
			if( $this->close_tag != '' ){
				
				$this->tag .= $this->close_tag;
				
				$this->close_tag = '';
				
			}
			
		}
		
		return $this;
		
	}

	private function attr( $attr ){
		
		if( empty( $attr ) ) return;
		
		if( is_array( $attr ) ){
			
			foreach( $attr as $key => $value )
				$a[] = $key.'="'.$value.'"';
			
			return ' '.implode( ' ', $a );
		
		}

		return $attr;
		
	}
	
	private function value( $value ){
		return is_callable( $value ) ? call_user_func( $value ) : $value;
	}
	
	public function exe(){
		
		$tag = $this->tag;
		
		$this->tag = '';
		
		return $tag;
		
	}
	
}

$html = new Html();

echo $html->tag( 'html',

						$html->tag( 'body',
						
											$html->tag( 'header',
											
																	$html->tag( 'h1', 'Header' )
											
											)->tag( 'footer',
																
																$html->tag( 'h1', 'Footer' )
																
											)
						
						)

	)->exe();
 

criric

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
21 Ago 2010
5.607
54
48
TN
header() è una funzione nativa di php
quando arrivi qui
PHP:
private function value( $value ){
        return is_callable( $value ) ? call_user_func( $value ) : $value;
    }
viene richiamata, ma, senza il parametro che si aspetta, di conseguenza lo script va in errore
 

Mr. PHP

Utente Attivo
31 Gen 2013
141
0
0
non ci sono header() nello script, cmq nn ho capito bene... quando viene richiamata la funzione value non mi restituisce i parametri ???
 

Mr. PHP

Utente Attivo
31 Gen 2013
141
0
0
Cmq non mi da nessun errore, diciamo che funziona solo che il codice html non è annidato come dovrebbe
 

criric

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
21 Ago 2010
5.607
54
48
TN
Nella funzione tag() richiami la funzione value() passando come parametro la stringa "Header"
PHP:
 $html->tag( 'header',
la funzione value() verifica se la stringa passata è una function e come spiegato prima và in errore.

edit:
restituisce un warning, probabilmente li hai disabilitati
Warning: header() expects at least 1 parameter, 0 given in C:\wamp\www\Develop\html.php on line 55
 

Mr. PHP

Utente Attivo
31 Gen 2013
141
0
0
Non so perche a me non mi visualizza nessun errore... cmq ho provato a togliere header ma il risultato non cambia mi restituisce il codice html sempre non in ordine...
 

Mr. PHP

Utente Attivo
31 Gen 2013
141
0
0
Scusami, ma l header viene passato come tag non come valore...
PHP:
$html->tag( tag /* header */, value, attr );
 

criric

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
21 Ago 2010
5.607
54
48
TN
metti degli echo nella funzione cosi vedi cosa arriva
PHP:
private function value( $value ){
        echo "valore funzione " . $value . "<br/>";
        return is_callable( $value ) ? call_user_func( $value ) : $value;
    }
 
Discussioni simili
Autore Titolo Forum Risposte Data
L [HTML] boostrap e class row HTML e CSS 2
B Estrarre TAG, ID e CLASS da un sorgente HTML. Javascript 1
C Assegnare una class ai ' TD ' presenti in uno script html Javascript 17
W class diagram per un semplice sito Html (con pochissimo php) HTML e CSS 0
X inserire file.class in html HTML e CSS 2
D [PHP] Fatal error: Class 'COM' not found in C:\..... PHP 6
D [PHP] Query in OOP class PHP 0
P [WordPress] header-post-title-class WordPress 7
P PHP OOP Brute Attack Class PHP 8
bubino8 [Javascript] Resize add/remove Class Javascript 1
trattorino css solo se richiama un class di un div HTML e CSS 1
E [PHP] Errore Class 'JText' not found CMS (Content Management System) 2
M Problemi tra GROUP BY e tabella 'datagrid.class.php' PHP 6
Erzsébeth Drag div con class Javascript 9
M Class extends proprieta vuote PHP 0
felino Override di una class "!important" HTML e CSS 1
M Function - Class + OOP Javascript 1
M blowfish.class.php PHP 0
S un consiglio database class OOP PHP 1
S database class problema PHP 3
P Richiamare id e class HTML e CSS 3
E Ajax...Class? Ajax 3
L Php user class ? setcookie PHP 2
D Class ziparchive e strana estensione del file PHP 2
catellostefano Problema con la classe class.phpmailer.php PHP 5
D reflection class che non riflette Flash 1
M Entity Class Programmazione 0
S Mysql + zip class PHP 0
cerbero id e class HTML e CSS 5
I Div class non centrato ... perchè? HTML e CSS 2
nourdine id e class HTML e CSS 1
A Class proprietà non visualizzabili esternamente Flash 0
S file .class HTML e CSS 1
B Java.class Programmazione 1
M variabile javascript su link html Javascript 0
G Pagina html in stringa PHP 2
E Sostituzione Elemento Html PHP 3
G Elementi HTML HTML e CSS 1
K Visualizzare del html responsive in una Webview Sviluppo app per Android 0
T Domanda valutazione html LinkedIn 2022 pt3 HTML e CSS 7
T Domanda valutazione html LinkedIn 2023 pt2 HTML e CSS 15
T Domanda valutazione html LinkedIn 2023 pt1 HTML e CSS 1
MarcoGrazia Salvataggio HTML in database PHP 2
K posizionare variabile da pagina html all'iframe. Javascript 1
peppe0703 Come Estrarre dati da db wordpress e richiamarli in html esterno HTML e CSS 0
L problema collegamento file css con html HTML e CSS 1
D Informazioni da XAMPP su HTML PHP 0
R Immagini html HTML e CSS 2
K File audio in html, chi mi può aiutare? HTML e CSS 0
K Aiuto con file audio in html HTML e CSS 1

Discussioni simili