Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/01/2012, 09:42
Hidek1
Colaborador
 
Fecha de Ingreso: octubre-2009
Ubicación: Tokyo - Japan !
Mensajes: 3.867
Antigüedad: 14 años, 6 meses
Puntos: 334
De acuerdo Aporte: Accesibilidad - Traductor a braille

Bueno hace mucho que no aporto en este foro así que dejo este código que realice hace unos días, el cual implementare en un proyecto futuro para la plataforma android !... el código originalmente lo tengo en python pero para dejarlo como herramienta en mi framework lo escribí también en PHP

Código PHP:
<?php
/**
 * Khaus Framework
 *
 * LICENSE
 *
 * This source file is subject to the Public license Creative Commons LPCC
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://creativecommons.org/licenses/by-nc/2.0/cl/
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * @category    Khaus
 * @package     Khaus_Accessibility
 * @copyright   Copyright (c) 2010 - 2011, Khaus Corp. Chile [[email protected]]
 * @license     Atribucion-Licenciar Igual 2.0 Chile. CC BY-NC 2.0
 * @version     1:20120106
 */
class Khaus_Accessibility_Braille
{
    private 
$_true 1;
    private 
$_false 0;
    private 
$_bin = array(
        
'a' => 1,   'b' => 5,   'c' => 3,   'd' => 11,
        
'e' => 9,   'f' => 7,   'g' => 15,  'h' => 13,
        
'i' => 6,   'j' => 14,  'k' => 17,  'l' => 21,
        
'm' => 19,  'n' => 27,  'o' => 25,  'p' => 23,
        
'q' => 31,  'r' => 29,  's' => 22,  't' => 30,
        
'u' => 49,  'v' => 53,  'w' => 46,  'x' => 51,
        
'y' => 59,  'z' => 57,  ' ' => 0,
    );
    
    
/**
     * Setea los valores de retorno, por defecto en los espacios
     * marcados del braile retorna 1 y en los no marcados un 0
     *
     * @param mixed $true
     * @param mixed $false 
     */
    
public function setReturnValues($true$false)
    {
        
$this->_true $true;
        
$this->_false $false;
    }
    
    
/**
     * Devuelve un array con cada letra en otro array con seis celdas en donde
     * se especifican los puntos prendidos y apagados del alfabeto braille.
     * 
     * @example
     * $access->braille('khaus');
     * 
     * @param string $string
     * @return array
     * @exception Exception si el string es invalido
     */
    
public function braille($string)
    {
        
$string = (string) strtolower($string);
        if (
preg_match('/^[a-z ]+$/'$string)) {
            
$returnBraille = array();
            for (
$i 0$o strlen($string); $i $o$i++) {
                
$key $string{$i};
                
$word = array();
                for (
$x 1$x <= 32$x $x << 1) {
                    
$word[] = $this->_bin[$key] & $x $this->_true $this->_false;
                }
                
$returnBraille[] = $word;
            }
            return 
$returnBraille;
        } else {
            throw new 
Exception('String invalido');
        }
    }
}
luego haré un update a mi framework que mantengo en Github para agregar esta librería,
quizá no sea de mucha utilidad en proyectos comunes... pero sirve para destacar que PHP da para muchas cosas, es solo cuestión de imaginar :)

dejo también un ejemplo de su uso y una foto del resultado

Código PHP:
<form action="" method="post">
    <input type="text" name="palabra" />
</form>
<?php
$access 
= new Khaus_Accessibility_Braille;
$access->setReturnValues('&circledcirc;''&xcirc;');
$palabra = isset($_POST['palabra']) ? $access->braille($_POST['palabra']) : array();
?>
<?php 
foreach ($palabra as $key => $value) : ?>
    <table style="display:inline-block;padding:3px;">
        <tr>
            <td><?php echo $value[0]; ?></td>
            <td><?php echo $value[1]; ?></td>
        </tr>
        <tr>
            <td><?php echo $value[2]; ?></td>
            <td><?php echo $value[3]; ?></td>
        </tr>
        <tr>
            <td><?php echo $value[4]; ?></td>
            <td><?php echo $value[5]; ?></td>
        </tr>
    </table>
<?php endforeach; ?>
---

---

si quieren consultar cualquier cosa no duden en hacerlo

saludos.
__________________
More about me...
~ @rhyudek1
~ Github