Comunidad de diseño web y desarrollo en internet online

Acentos y ñ en php/Flash

Citar            
MensajeEscrito el 04 Sep 2009 10:05 pm
Hola amigos de Cristalab.
Estoy adaptando un libro de visitas que funciona en Flash, cargando variables desde un archivo php. Es conocido, de flash-db.com y ya ví que lo recomendaban en algunos post de Clab.
El libro me funciona correctamente, salvo que no salen acentos ni ñ entre otros caracteres.
Ya modifiqué algunas líneas del archivo php hasta donde me dio mi capacidad, pero no pude resolver este tema por más lectura de ayudas y post relacionados con este tema que he recorrido, quedando estancado, ya que no sé cómo ni donde escribir dentro del php el código para que reconozca acentos, ñ y otros caracteres especiales.
A continuación el php en cuestión, y desde ya gracias por su ayuda.

Código PHP :

<?php

// If you are using an old version of php, remove the next set of lines.
// or use $HTTP_POST_VARS["..."] instead.

$Submit = $_POST["Submit"];
$Nombre = $_POST["nombreV"];
$Email = $_POST["emailV"];
$Barrio = $_POST["barrioV"];
$Comentario = $_POST["comentarioV"];
$NumLow = $_REQUEST["NumLow"];
$NumHigh = $_REQUEST["NumHigh"];

// Replace special characters - you can remove the next 5 lines if wanted.
$Nombre = ereg_replace("[^A-Za-z0-9 ]", "", $Nombre);
$Email = ereg_replace("[^A-Za-z0-9 @.-/']", "", $Email);
$Comentario = ereg_replace("[^A-Za-z0-9 @.-/]", "", $Comentario);
$Barrio = ereg_replace("http://", "", $Barrio);
$Barrio = ereg_replace("[^A-Za-z0-9 @.-/:]", "", $Barrio);

// Remove slashes.
$Nombre = stripslashes($Nombre);
$Email = stripslashes($Email);
$Barrio = stripslashes($Barrio);
$Comentario = stripslashes($Comentario);

// ###################################################################################
// ########## Reading and Writing the new data to the GuestBook Database #############

if ($Submit == "Yes") {

// Next line tells the script which Text file to open.
// La siguiente línea le dice a la secuencia de comandos que el archivo de texto para abrir.
$filename = "GuestBook.txt";

// Opens up the file declared above for reading 

$fp = fopen( $filename,"r"); 
$OldData = fread($fp, 80000); 
fclose( $fp ); 

// Gets the current Date of when the entry was submitted
$Today = (date ("d/m/Y",time()));


// Puts the recently added data into html format that can be read into the Flash Movie.
// You can change this up and add additional html formating to this area. For a complete listing of all html tags
// you can use in flash - visit: http://www.macromedia.com/support/flash/ts/documents/htmltext.htm

$Input = "Nombre: <b>$Nombre</b><br>Barrio: <b><u>$Barrio</u></b><br>Comentarios: <b>$Comentario</b><br><i><font size="-1">Fecha: $Today</font><br><br>.:::.";

/* This Line adds the '&GuestBook=' part to the front of the data that is stored in the text file. This is important because without this the Flash movie would not be able to assign the variable 'GuestBook' to the value that is located in this text file */

$New = "$Input$OldData";

// Opens and writes the file.

$fp = fopen( $filename,"w"); 
if(!$fp) die("&GuestBook=cannot write $filename ......&");
fwrite($fp, $New, 800000); 
fclose( $fp ); 
}

// ###################################################################################
// ######### Formatting and Printing the Data from the Guestbook to the Flash Movie ##



// Next line tells the script which Text file to open.
// La siguiente línea le dice a la secuencia de comandos que el archivo de texto para abrir.
$filename = "GuestBook.txt";

// Opens up the file declared above for reading 

$fp = fopen( $filename,"r"); 
$Data = fread($fp, 800000); 
fclose( $fp );

// Splits the Old data into an array anytime it finds the pattern .:::.
$DataArray = split (".:::.", $Data);

// Counts the Number of entries in the GuestBook
$NumEntries = count($DataArray) - 1;

print "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&GuestBook=";
for ($n = $NumLow; $n < $NumHigh; $n++) {
print $DataArray[$n];
if (!$DataArray[$n]) {
Print "<br><br><b>No hay mas comentarios</b>";
exit;
}
}
?>

Por CRD

80 de clabLevel



Genero:Masculino  

Diseño Filete Ilustración

firefox
Citar            
MensajeEscrito el 04 Sep 2009 10:16 pm
Abre tu php con el block de notas. Después guárdalo como y verifica que su codificación sea UTF-8 :)

Espero te sirva, sino acá andamos.

Por violetisha

575 de clabLevel

1 tutorial
1 articulo

Genero:Femenino  

Mi silla en el estudio, México

opera
Citar            
MensajeEscrito el 04 Sep 2009 11:15 pm
Probé, lo abrí y me aseguré de guardarlo como utf-8 pero sigue sin funcionar.
El libro está en este link www.pizzeriaelfortin.com.ar en la sección "gente" y, dentro de ésta, aparece una opción libro > firmar el libro. Justamente unos campos dinámicos "levantan" los mismos datos ingresados, y aqui sí se muetran los caracteres.

Por CRD

80 de clabLevel



Genero:Masculino  

Diseño Filete Ilustración

firefox
Citar            
MensajeEscrito el 04 Sep 2009 11:27 pm
Bien, ahora verifica que los campos de texto dinámico tengan el Latin I incorporado.

Espero que esto sí te sirva. Saludos! ^^

Por violetisha

575 de clabLevel

1 tutorial
1 articulo

Genero:Femenino  

Mi silla en el estudio, México

opera
Citar            
MensajeEscrito el 05 Sep 2009 02:36 am
Probé ese cambio pero no fue favorable. Me parece que en el php hay que poner utf8_decode() pero no encuentro donde. Creo que debería ser en la linea que arma el Imput. Probé poniendo por ej. utf8_decode($Nombre) pero en lugar de ver por ej. José, se veía utf8_decode(Jos).

Por CRD

80 de clabLevel



Genero:Masculino  

Diseño Filete Ilustración

firefox
Citar            
MensajeEscrito el 05 Sep 2009 02:40 am
De paso aclaro esto: si el visitante escribe "Soy José el panameño", en los comentarios se imprime "Soy Jos el panameo".

Por CRD

80 de clabLevel



Genero:Masculino  

Diseño Filete Ilustración

firefox
Citar            
MensajeEscrito el 05 Sep 2009 02:42 am
Ooook, la verdad, no había leido tu script :P, pero tal vez si abres GuestBook.txt y verificas que esté codificado como UTF-8, arregle el problema... No creo que tengas que usar utf8_decode o utf8_encode.

Saludos.

Por violetisha

575 de clabLevel

1 tutorial
1 articulo

Genero:Femenino  

Mi silla en el estudio, México

opera
Citar            
MensajeEscrito el 05 Sep 2009 02:57 am
Bueno gracias. El txt también está en utf-8. Tengo otro script que me alerta vía mail sobre un nuevo comentario, y ese llega con todos los caracteres. Allí usa utf8_decode().

Por CRD

80 de clabLevel



Genero:Masculino  

Diseño Filete Ilustración

firefox
Citar            
MensajeEscrito el 05 Sep 2009 03:12 am
Ya está! :D Tu código va así:

Código PHP :

<?php
// If you are using an old version of php, remove the next set of lines.
// or use $HTTP_POST_VARS["..."] instead.
$Submit    = $_POST["Submit"];
$Name       = $_POST["Name"];
$Email       = $_POST["Email"];
$Website    = $_POST["Website"];
$Comments    = $_POST["Comments"];
$NumLow    = $_REQUEST["NumLow"];
$NumHigh    = $_REQUEST["NumHigh"];

// Replace special characters - you can remove the next 5 lines if wanted.
//$Name       = ereg_replace("[^A-Za-z0-9 ]", "", $Name);
//$Email       = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Email);
//$Comments   = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Comments);
//$Website    = eregi_replace("http://", "", $Website);
//$Website    = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~\:]", "", $Website);

// Remove slashes.
$Name       = stripslashes($Name);
$Email       = stripslashes($Email);
$Website    = stripslashes($Website);
$Comments    = stripslashes($Comments);

// ###################################################################################
// ########## Reading and Writing the new data to the GuestBook Database #############

if ($Submit == "Yes") {
// Next line tells the script which Text file to open.
   $filename    = "GuestBook.txt";

// Opens up the file declared above for reading 

   $fp       = fopen( $filename,"r"); 
   $OldData    = fread($fp, 80000); 
   fclose( $fp ); 

// Gets the current Date of when the entry was submitted
   $Today       = (date ("l dS of F Y ( h:i:s A )",time()));

// Puts the recently added data into html format that can be read into the Flash Movie.
// You can change this up and add additional html formating to this area.  For a complete listing of all html tags
// you can use in flash - visit: http://www.macromedia.com/support/flash/ts/documents/htmltext.htm

   $Input = "Name: <b>$Name</b><br>Email: <b><u><a href=\"mailto:$Email\">$Email</a></u></b><br>Website: <b><u><a href=\"http://$Website\" target=\"_blank\">$Website</a></u></b><br>Comments: <b>$Comments</b><br><i><font size=\"-1\">Date: $Today</font><br><br>.:::.";

/* This Line adds the '&GuestBook=' part to the front of the data that is stored in the text file.  This is important because without this the Flash movie would not be able to assign the variable 'GuestBook' to the value that is located in this text file  */

   $New = "$Input$OldData";

// Opens and writes the file.

   $fp = fopen( $filename,"w"); 
   if(!$fp) die("&GuestBook=cannot write $filename ......&");
   fwrite($fp, $New, 800000); 
   fclose( $fp ); 
}

// ###################################################################################
// ######### Formatting and Printing the Data from the Guestbook to the Flash Movie ##



// Next line tells the script which Text file to open.
   $filename = "GuestBook.txt";

// Opens up the file declared above for reading 

   $fp    = fopen( $filename,"r"); 
   $Data    = fread($fp, 800000); 
   fclose( $fp );

// Splits the Old data into an array anytime it finds the pattern .:::.
   $DataArray = split (".:::.", $Data);

// Counts the Number of entries in the GuestBook
   $NumEntries = count($DataArray) - 1;

   print "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&GuestBook=";
   for ($n = $NumLow; $n < $NumHigh; $n++) {
   print $DataArray[$n];
      if (!$DataArray[$n]) {
         Print "<br><br><b>No More entries</b>";
      exit;
      }
   }
?>


Nota que sólo comenté las lineas en donde dice: Replace special characters - you can remove the next 5 lines if wanted. Que en su traducción sería: Reemplazar caracteres especiales - puedes remover las siguientes 5 lineas si quieres.

Ahora, sí... Sé que te servirá. Saludos. ^^

Por violetisha

575 de clabLevel

1 tutorial
1 articulo

Genero:Femenino  

Mi silla en el estudio, México

opera
Citar            
MensajeEscrito el 06 Sep 2009 06:39 pm
Muchas gracias, lo voy a probar y te comento.

Por CRD

80 de clabLevel



Genero:Masculino  

Diseño Filete Ilustración

msie8
Citar            
MensajeEscrito el 06 Sep 2009 07:11 pm

Por CRD

80 de clabLevel



Genero:Masculino  

Diseño Filete Ilustración

msie8
Citar            
MensajeEscrito el 07 Sep 2009 06:18 am
:) Muy bien!

Un gusto haberte podido ayudar. ^^

Saludos!

Por violetisha

575 de clabLevel

1 tutorial
1 articulo

Genero:Femenino  

Mi silla en el estudio, México

opera
Citar            
MensajeEscrito el 07 Abr 2010 09:23 am
Hola compañeros!

Encontre la solucion a vuestro problema , yo intentaba leer de un archivo txt, pero cuando encontraba un accento o una " Ñ " me aparecia un rombo con un interrogante dentro.

Solución: Justo despues de haber abierto la etiqueta " <?php " Poned:


header('Content-Type: text/html; charset=iso-8859-1');


y seguido vuestro codigo para leer el fichero

Un saludo

Aitor
3DE
Diseño Web
http://www.bsibility.com/

Por darkram

0 de clabLevel



 

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.