Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/02/2008, 06:30
Eduardo79
 
Fecha de Ingreso: mayo-2007
Mensajes: 17
Antigüedad: 17 años
Puntos: 0
Como realizar un lexemador con este codigo

hola amigos necesito hacer en php algo como esto teniendo un archivo txt con esta informacion por ejemplo

Hola a todos 10/5

345.26 kp65ku ++7)


fin


deseo ver que al momento de leer el archivo me muestre la informacion asi

Línea 1
Lexema 1: Hola
Lexema 2: a
Lexema 3: todos
Lexema 4: 10
Lexema 5: /
Lexema 6: 5
Línea 2
Línea 3
Lexema 1: 345.26
Lexema 2: kp65ku
Lexema 3: +
Lexema 4: +
Lexema 5: 7
Lexema 6: )
Línea 4
Línea 5
Línea 6
Lexema 1: Fin



el codigo que he hecho pero que no me funciona al 100% es el siguiente:

<?php
$ruta = 'lectura.txt';
if($file = fopen($ruta, 'r')){
echo "<center><table border = 0>";
$i = 1;
while(!feof($file)){
$linea = fgets($file);
echo "<tr><td>Linea: $i</td></tr>";
//echo "<tr><td>$linea</td></tr>";
$lexemas = explode (' ', $linea);
$lexemas1 = explode ('+-/', $linea);
$lexemas2 = explode ('1324567890', $linea);
$lexemas3 = explode (',', $linea);
if ($linea <> ""){
$lexe = 0;
if ($lexemas[0] <> ""){
$lexe = ($lexe + 1);
echo "<tr><td>Lexema $lexe:$lexemas[0]</td></tr>";
}
if ($lexemas[1] <> ""){
$lexe =($lexe+1);
echo "<tr><td>Lexema $lexe:$lexemas[1]</td></tr>";
}
if ($lexemas[2] <> ""){
$lexe = ($lexe+1);
echo "<tr><td>Lexema $lexe:$lexemas[2]</td></tr>";
}



$linea = "";
}

$i = $i + 1;
}
echo "</table></center>";
fclose($file);
}
else{
echo "<br><b>Archivo no encontrado</b>";
}

?>

si alguien puede ayudarme, mil gracias...