Foros del Web » Programando para Internet » PHP »

Php form > .txt utf-8

Estas en el tema de Php form > .txt utf-8 en el foro de PHP en Foros del Web. Holas, he visto los temas relacionados y no he encontrado la forma de aplicarlo a mi código, o no he sabido hacerlo. Lo que necesito ...
  #1 (permalink)  
Antiguo 27/07/2009, 14:48
Avatar de hucasys  
Fecha de Ingreso: noviembre-2001
Ubicación: Bastante buena...
Mensajes: 816
Antigüedad: 22 años, 5 meses
Puntos: 3
Información Php form > .txt utf-8

Holas, he visto los temas relacionados y no he encontrado la forma de aplicarlo a mi código, o no he sabido hacerlo.
Lo que necesito es forzar a que el archivo txt generado sea codificado rtf-8 para que me lo lea Flash.
Cualquier ayuda se agradecerá. ;)

Dejo el código:
Código PHP:
<?php
  $saving 
$_REQUEST['saving'];
  if (
$saving == 1) { 
    
$data $_POST['data'];
    
$file "data.txt"

 
    
$fp fopen($file"w") or die("Couldn't open $file for writing!");
    
fwrite($fp$data) or die("Couldn't write values to file!"); 
 
    
fclose($fp); 
    echo 
"Saved to $file successfully!";
  }
?>
<meta http-equiv="Content-type" value="text/html; charset=UTF-8" />

<form name="form1" method="post" action="form.php?saving=1">
  <textarea name="data" cols="100" rows="10">
  <?php
    $file 
"data.txt";
    if (!empty(
$file)) {  
      
$file file_get_contents("$file");
      echo 
stripslashes($file);  
    }  
  
?>
  </textarea>
  <br>
  <input type="submit" value="Save">
</form>
__________________
La manera en que resuelves el problema, es el problema.
ROBERT FRIPP
  #2 (permalink)  
Antiguo 27/07/2009, 14:53
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Php form > .txt utf-8

Tu script debe estar codificado en utf-8 y, al crear el archivo, hazlo en modo binario:

$fp = fopen($file, "wb") or die("Couldn't open $file for writing!");
__________________
- León, Guanajuato
- GV-Foto
  #3 (permalink)  
Antiguo 27/07/2009, 17:44
Avatar de hucasys  
Fecha de Ingreso: noviembre-2001
Ubicación: Bastante buena...
Mensajes: 816
Antigüedad: 22 años, 5 meses
Puntos: 3
De acuerdo Respuesta: Php form > .txt utf-8

Hola Triby, gracias, ya lo había probado codificado, pero no creando en modo binario. Voy a probar.
Salut
__________________
La manera en que resuelves el problema, es el problema.
ROBERT FRIPP
  #4 (permalink)  
Antiguo 03/08/2009, 16:31
Avatar de hucasys  
Fecha de Ingreso: noviembre-2001
Ubicación: Bastante buena...
Mensajes: 816
Antigüedad: 22 años, 5 meses
Puntos: 3
Respuesta: Php form > .txt utf-8

He probado con el código de esta manera, pero sigue sin funcionar:
Código:
<?php
header ('Content-type: text/html; charset=utf-8');
  $saving = $_REQUEST['saving'];
  if ($saving == 1) { 
    $data = $_POST['data'];
	$file = "data.txt"; 

 
    $fp = fopen($file, "wb") or die("Couldn't open $file for writing!");
    fwrite($fp, $data) or die("Couldn't write values to file!"); 
 
    fclose($fp); 
    echo "Saved to $file successfully!";
  }
?>

<meta http-equiv="Content-type" value="text/html; charset=UTF-8" />
<form name="form1" method="post" action="form.php?saving=1">
  <textarea name="data" cols="100" rows="10">
  <?php
   
    $file = "data.txt";
    if (!empty($file)) {  
	  $file = file_get_contents("$file");
	  echo stripslashes($file);  
	}  
?>
  </textarea>
  <br>
  <input type="submit" value="Save">
</form>
Y me imprime el siguiente error:
Warning: Cannot modify header information - headers already sent by (output started at.........................

¿Ideas?
__________________
La manera en que resuelves el problema, es el problema.
ROBERT FRIPP
  #5 (permalink)  
Antiguo 03/08/2009, 16:38
 
Fecha de Ingreso: enero-2009
Mensajes: 408
Antigüedad: 15 años, 3 meses
Puntos: 14
Respuesta: Php form > .txt utf-8

Estimado hucasys , el error que usted publica es debido a que no se puede enviar nada al navegador antes de una cabecera , no pueden existir ni espacios en blanco , ni nada similar.

Por otro lado he probado su codigo y dicho error no me figura.

Saludos!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:28.