Código PHP en Blogger, formateando tu código
1 <!— Form for code –>
2 <form action=”<?php echo $_SERVER['PHP_SELF']; ?>” method=”post” style=”margin-bottom: 40px;”><div id=”formulario”>
3 <textarea rows=”20″ cols=”80″ name=”codigo”></textarea><br />
4 <input type=”submit” name=”enviar” value=”Formatear” /></div>
5 </form>
6 <?php
7 if( !empty( $_POST['codigo'] ) ) {
8 $codigo = $_POST['codigo'];
9 $codigo = str_replace( “\t”, ” “, $codigo );
10 $codigo = highlight_string( stripslashes( $codigo ), true );
11
12 $line = 1;
13 $buffer = array();
14 $cod = explode( “<br />”, $codigo );
15 foreach( $cod as $codLine ) {
16 $buffer[] = “<b>$line</b> ” . $codLine;
17 $line++;
18 }
19
20 $codigo = implode( “<br />”, $buffer );
21 // HACK:
22 $codigo = str_replace( “<b>1</b> <code>”, “<code><b>1</b> ”, $codigo );
23 echo ‘<div id=”formated” style=”border: double #dfdfdf;”><h3> Este es tu código formateado </h3>’;
24 echo ‘<p>’.$codigo.‘</p><hr />’;
25 //Gets the source from a file previously created and modified
26 $abrir=fopen(“tmp.txt”, “w”); //open file
27 fwrite($abrir, $codigo); //save code obtained previously
28 fclose($abrir); //close file
29 $url = ‘http://formatealo.terysoftware.com/tmp.txt’;
30 $lineas = file($url);
31 for ($i = 0; $i <count($lineas); $i++) {
32 $resultado = $resultado.htmlentities($lineas[$i]).“<br />”;
33 }
34
35 echo ‘<h3>Inserta este código en tu sitio </h3>’.$resultado.‘</div>’;
36 }
37 ?>
38
39 </div>
