Ver Mensaje Individual
  #17 (permalink)  
Antiguo 15/01/2010, 16:00
Avatar de neodani
neodani
 
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 1 mes
Puntos: 20
Respuesta: Encontrar etiquetas html, class y id's (con expresiones regulares)

No me lo puedo creer fui capaz :D

Código PHP:
Ver original
  1. /*
  2. Busca todos los tags HTML.
  3. Puedes indicar cuales quieres excluir, dentro de la expresión regular.
  4. En el ejemplo, se excluyen (meta,title,body y head)
  5. */
  6. function Extraer_Tags_HTML($html){
  7.     preg_match_all('/<(?!meta|title|body|head)(\w+)[^>]*\/?>/',$html,$matches);
  8.     $sin_duplicados=array_unique($matches[1]); //elimina los tags HTML repetidos
  9.    
  10.     return $sin_duplicados;
  11. }
  12.  
  13. // Imprime el array de tags HTML
  14. $resultado=Extraer_Tags_HTML($html);
  15. foreach($resultado as $value)
  16.     echo $value . "<br/>";

Ahora solo falta la otra parte del post diferenciar las clases y los id's del estilo

Tengo lo siguiente, gracias a la ayuda abimaelrc

Código PHP:
Ver original
  1. <?
  2. /* SACAR TODAS LAS ETIQUETAS, ID Y CLASES DEL ESTILO CSS */
  3. $html='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es">
  5. <head>
  6.     <title>Área restringida | Panel de Administración</title>
  7.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  8.     <meta name="robots" content="noindex,nofollow"/>
  9.     <link rel="stylesheet" href="/css/entrada_login.css" type="text/css" media="all" />
  10.     <!-- Favicon -->
  11.     <link rel="shortcut icon" href="/imagenes/favicon.ico"/>
  12. </head>
  13. <body class="login">
  14.     <p id="borde-top"><a class="enlace_top" href="entrada_login.php" title="Panel de Administración">ATENCIÓN: Área privada.</a></p>
  15.     <!-- Formulario Entrada -->
  16.     <div id="login">
  17.         <h1 id="titulo" title="Panel de Administración"></h1>
  18.  
  19.         <form id="loginform" action="includes/login.php" method="post">
  20.             <p>
  21.                 <label>Nombre de usuario<br />
  22.                 <input type="text" name="user" id="user_login" class="input" value="" size="20" tabindex="1" accesskey="1"/></label>
  23.             </p>
  24.             <p>
  25.                 <label>Contraseña<br />
  26.                 <input type="password" name="password" id="user_pass" class="input" value="" size="20" tabindex="2" accesskey="2" /></label>
  27.             </p>
  28.             <p class="forgetmenot"><label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="90" /> Recordarme</label></p>
  29.             <p class="submit">
  30.                 <input type="submit" name="wp-submit" id="wp-submit" value="Iniciar Sesión" tabindex="100" />
  31.             </p>
  32.         </form>
  33.         <p id="nav">
  34.             <a class="footer" href="#">Área privada.</a>
  35.         </p>
  36.     </div>
  37.     </body>
  38. </html>
  39. ';
  40.  
  41.  
  42. preg_match_all('/<(a|p|form|h1|label|input|div|body)[^>](?:(class|id)="(.*?)")[^>]*>/is',$html,$matches);
  43. echo "<pre>";
  44. print_r($matches);
  45.  
  46. foreach($matches[3] as $item)
  47. {
  48.   print "$item<br/>" ;
  49. }
  50. echo "</pre>";
  51. echo "<br/>";