fork download
  1. <?php
  2.  
  3. $html = '<td style="background-color:#b0c400;border-bottom:1px solid #ffffff;text-align:right;padding:0px 5px 0px 5px;color:#000000;">2769</td>';
  4.  
  5. //Generar el DOM
  6. $dom = new DOMDocument;
  7. $dom->loadHTML($html, LIBXML_COMPACT | LIBXML_HTML_NOIMPLIED | LIBXML_NONET);
  8.  
  9. //Eliminar todos los tags
  10. $sin_tags = $dom->textContent;
  11.  
  12. echo "Contenido de texto de toda la página:\n" . $sin_tags; // => 2769
  13.  
  14.  
  15. //Obtener todos los TD
  16. $td_nodelist = $dom->getElementsByTagName('td');
  17. //Obtener el primer TD
  18. $td = $td_nodelist->item(0);
  19.  
  20. //Obtener el contenido de texto del tag
  21. $numero = $td->textContent;
  22.  
  23. echo "\n\nContenido del TD:\n" . $numero; // => 2769
Runtime error #stdin #stdout #stderr 0.01s 82880KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Fatal error:  Uncaught Error: Class 'DOMDocument' not found in /home/UyNb82/prog.php:6
Stack trace:
#0 {main}
  thrown in /home/UyNb82/prog.php on line 6