Reputation: 3158
Is there any PHP framework/library that allows me to do something like:
$element = $html->getElementByName("name");
$element->changeAttribute("class", "myClass");
echo $html->display;
I know that something like this is possible with javascript, but I need it to be PHP.
Upvotes: 1
Views: 70
Reputation: 2485
Example:
<?php
$doc = new DOMDocument();
$doc->load( 'books.xml' );
$books = $doc->getElementsByTagName( "book" );
foreach( $books as $book )
{
$authors = $book->getElementsByTagName( "author" );
$author = $authors->item(0)->nodeValue;
$publishers = $book->getElementsByTagName( "publisher" );
$publisher = $publishers->item(0)->nodeValue;
$titles = $book->getElementsByTagName( "title" );
$title = $titles->item(0)->nodeValue;
echo "$title - $author - $publisher\n";
}
?>
Just use DOMDocument class (For HTML use loadHTMLFile
or loadHTML
instead of load
)
Upvotes: 1
Reputation: 5227
Check out the various methods in the DOMDocument class. Of course, remember that you need to load your html into a DOMDocument object using loadHTML before you can manipulate it.
Upvotes: 2