[PHP] Odpowiedniki JavaScriptowych document.getElementBy

Proszę o podanie (o ile istnieją) odpowiedniki JavaScriptowych document.getElementById, document.getElementsByClassName, document.createElement, i.t.d. dla PHP.

Jeśli chodzi Ci o obsługe XML’a to możesz użyć Simplexml:

http://php.net/manual/en/book.simplexml.php

parser HTML’a:

http://simplehtmldom.sourceforge.net/

albo napisz trochę jaśniej o co Ci chodzi

Wszystko masz tu http://www.php.net/manual/en/book.dom.php

getElementById http://www.php.net/manual/en/domdocumen … ntbyid.php

createElement http://www.php.net/manual/en/domdocumen … lement.php

Trzeba mieć w pamięci, że XML !== HTML :slight_smile:

Co do tego: http://simplehtmldom.sourceforge.net/ - nie używałem, ale z tego co widzę w dokumentacji, może być bardzo użyteczne.

Ale nic nie stoi na przeszkodzie, żeby tworzyć/edytować tym poprawny kod xhtml. Da się. Zrobiłem w tym kiedyś dawno temu całą stronę internetową, która poprawnie przechodziła przez http://validator.w3.org/.

Dla XML jest tak, a jak jest dla HTML?

<?php


$dom = new DOMDocument('1.0', 'utf-8');


$element = $dom->createElement('test', 'This is the root element!');


// We insert the new element as root (child of the document)

$dom->appendChild($element);


echo $dom->saveXML();

?>

http://www.php.net/manual/en/domdocument.savehtml.php