07 julio 2013

Leer Fichero de texto con PHP

Con este código podremos leer un fichero de texto linea  a linea y mostrarlo en pantalla:

<?php
     $file = fopen("file.txt", "r") or exit("Unable to open file!");
     while(!feof($file) {
          echo fgets($file). "<br />";
          }
     fclose($file);
  ?>


06 julio 2013

Reordenar aleatoriamente un vector Javascript

Esta función sirve para reordenar los elementos de un array de forma aleatoria:

Array.prototype.shuffle = function() {
    for ( var i = this.length-1; i ]]
>
 0; i-- ) {
        var j = Math.floor( i * Math.random() );
        var tmp = this[ j ];
        this[ j ] = this[ i ];
        this[ i ] = tmp;
    }
    return this;
}