user1091856
user1091856

Reputation: 3158

PHP Framework that allows me to deal with HTML?

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

Answers (3)

SlavaNov
SlavaNov

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

Aaron
Aaron

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

PeeHaa
PeeHaa

Reputation: 72682

No need for a framework. Just use PHP's DOMDocument.

Upvotes: 4

Related Questions