Sentido Web

Referencias y explicaciones sobre desarrollo web, PHP, Ajax, XHTML, MySQL ...

Archivo para la etiqueta ‘parse’

17Feb
2009
Comments Off

Parsear HTML con PHP

Para obtener datos de un HTML, en vez de hacerlo con expresiones regulares, hacerlo mediante DOMDocument: $oldSetting = libxml_use_internal_errors( true ); libxml_clear_errors(); $html = new DOMDocument(); $html->loadHtmlFile( $url ); $xpath = new DOMXPath( $html ); $links = $xpath->query( ‘//a’ ); foreach ( $links as $link ) { echo $link->getAttribute( ‘href’ ), “\n”; } libxml_clear_errors(); libxml_use_internal_errors( [...]