Precedente :: Successivo |
Autore |
Messaggio |
sevenjeak Semidio


Registrato: 04/02/08 22:05 Messaggi: 308 Residenza: Roma
|
Inviato: 24 Set 2009 15:52 Oggetto: Php,Dom e Html |
|
|
Salve,
Ho fatto uno script di provo che mi crea una pagina html. Lo script ha questo codice:
Codice: |
<?php
$doc = new DOMdocument('1.0');
$doc->formatOutput = true;
$root = $doc->createElement('html');
$root = $doc->appendChild($root);
$body = $doc->createElement('body');
$doby = $root->appendChild($body);
$text = $doc->createTextNode('Script creato con PHP/DOM');
$text = $body->appendChild($text);
$doc->saveHTMLFile('rs.html');
?>
|
Lo script funzione, solo che, volevo sapere:
· Come inserire il doctype all'inizio del codice?
· Come inserire attributi e i suoi valori?
· Come mai il codice html viene scritto su una sola riga? |
|
Top |
|
 |
freemind Supervisor sezione Programmazione


Registrato: 04/04/07 21:28 Messaggi: 4643 Residenza: Internet
|
Inviato: 27 Set 2009 18:19 Oggetto: |
|
|
Ciao,
prova a guardare qui
Tratto da pointbeing.net
Citazione: |
I've recently been spending quite a lot of time with PHP's DOM extension, which is extremely useful for both generating and parsing XML.
In this particular case, I'm generating XML, and it's imperative that the XML markup which the code is generating should contain a Doctype declaration (DTD). It isn't hard to do that using DOM, but it did take a little bit of hunting around in the manual and online, so here's a quick overview of how to add a Doctype declaration to a DOMDocument.
Of course, there isn't anything as handy as, say, $document->addDoctype('xhtml'), that would be too easy. Instead, the first step is to instance DOMImplementation, and have that create an instance of DOMDocumentType.
Once the DOMDocumentType object has been created, it can be passed as a parameter to DOMImplementation::createDocument(), which returns a DOMDocument that you can start working with.
(continua)
|
|
|
Top |
|
 |
sevenjeak Semidio


Registrato: 04/02/08 22:05 Messaggi: 308 Residenza: Roma
|
Inviato: 27 Set 2009 19:13 Oggetto: |
|
|
Non ho capito tanto visto che è in inglese.
Potresti farmi un piccolo esempio o postarmi un post in italiano, se puoi?
P.S.: mi sono ricordado solo ora che la pagina si poteva traturre, cmq per non farlo scrivere righa per righa? |
|
Top |
|
 |
freemind Supervisor sezione Programmazione


Registrato: 04/04/07 21:28 Messaggi: 4643 Residenza: Internet
|
Inviato: 30 Set 2009 20:45 Oggetto: |
|
|
Preso secco secco da php.net
Codice: | <?php
$doctype = DOMImplementation::createDocumentType("html",
"-//W3C//DTD HTML 4.01//EN",
"http://www.w3.org/TR/html4/strict.dtd");
$doc = DOMImplementation::createDocument(null, 'html', $doctype);
?> |
Prova un po' e facci sapere.
Per l'andare a capo non so, il fatto che tu veda il sorgente html generato in una sola riga è normale perchè i vari metodi non aggiungono il "\n"; non so se sia possibile mettercelo. |
|
Top |
|
 |
|
|
Non puoi inserire nuovi argomenti Non puoi rispondere a nessun argomento Non puoi modificare i tuoi messaggi Non puoi cancellare i tuoi messaggi Non puoi votare nei sondaggi
|
|