14.5.07

PhP - Indentador V 1.0

Al fin he conseguido crear una versión funcional del "Indentador de Código para Entornos Htm" ICEH ('hieloh'[x'DDD]).

Ten encuenta que para poder visualizar correctamente el codigo he añadido el caracter "·" en la sección de "str_replace" justo después del Ampersand, "&". Para que funcione tienes que eliminar esos puntos.

Ya sin más, el código:

<!--  ------------------ -->
<!-- | By Aladaris 2007 |-->
<!--  ------------------ -->
<!-- Se hace uso del script descargar.php obtenido en http://www.php.net -->
<html>
<head>
  <title>Indentador</title>
</head>
<body>
<?
   if(trim($HTTP_POST_VARS["inicial"]) != "")
   {
      $code = $HTTP_POST_VARS["inicial"];
      $code = str_replace("<","&·lt;",$code);
      $code = str_replace(">","&·gt;",$code);
      $code = str_replace(" ","&·nbsp;",$code);
      $code = str_replace("\'","&·#39;",$code);
      $code = str_replace('\"',"&·quot;",$code);
      $code = str_replace("\\\\","&·#92",$code);                     
      $code = nl2br($code);   // Sustituimos los saltos de línea por <br>
      $salida = fopen("identado.txt","w");
      fputs($salida, $code);
      fclose($salida);
      echo ('<div><a href="descargar.php?f=identado.txt">Descargar codigo identado</a></div>');
   }
   else
   { ?>
      <FORM ACTION="identador.php" METHOD="post">
         <textarea name="inicial" cols="120" rows="40" id="inicial"></textarea></br>
         <input type="submit" value="Identar">
      </form>
<? } ?>
</body>
</html>

Si ya has mirado el código, habrás comprobado que se hace uso de un script externo llamado descargar.php, y tal y como se cita en la cabecera del código, lo extraje de la web php.net. Paso a copiar el código del script de descarga (repito, no es mio, aunque se sigue ajustando a la filosofia del blog):

<?php
//Script conseguido en http://www.php.net/
    $archivos = array("identado.txt", "identador.php", "descargar.php");
    $f = $_GET["f"];
    if(strpos($f,"/")!==false){
        die("No puedes navegar por otros directorios");
    }
    if(!in_array($f,$archivos)){
        die("<b>ERROR!</b> no tienes permiso descargar $f");
    }
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"$f\"\n");
    $fp=fopen("$f", "r");
    fpassthru($fp);
?>

----- Pendiente por publicar -----
*Comentarios extendidos del code

1 comentario:

Anónimo dijo...

Concern Fresh Wind offers a invest money in building for different tariff plans. Recently, many, survivors overcame the recent financial crisis, more began to wonder where better to invest. According to conclusions of many of the leading the best analysts, one of the most investing money in building. It is well known Everyone knows that the construction of less exposed to the risk of falling prices, in addition , construction has always been important and in demand, and will be in demand. Even the economic crisis did not recaptured removed the desire for people to buy their own property. Therefore, investment in construction will always remain relevant and profitable.

Fwit Biz - [url=https://fwit.biz]where to invest the money to earn[/url]