Foros del Web » Programando para Internet » PHP »

Problemas con los caracteres

Estas en el tema de Problemas con los caracteres en el foro de PHP en Foros del Web. Hola buenas, pues cuando pongo una "ñ" o algúna tilde, me sale un caracter de un rectángulo con un simbolo de interrogante "?" He intentado ...
  #1 (permalink)  
Antiguo 27/06/2011, 06:59
Avatar de thefranex3  
Fecha de Ingreso: junio-2011
Mensajes: 21
Antigüedad: 12 años, 10 meses
Puntos: 0
Pregunta Problemas con los caracteres

Hola buenas, pues cuando pongo una "ñ" o algúna tilde, me sale un caracter de un rectángulo con un simbolo de interrogante "?"

He intentado con esto:

Código PHP:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
Pero no funciona, esta es la página:

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Buscador de Canarismos</title>
<html>
<head>
<style>
A:link          {text-decoration: none; color: #11116E;}
A:visited       {text-decoration: none; color: #11116E;}
A:hover          {font-style: normal; color: #000000; text-decoration: underline;}
BODY             {font-family: Verdana; font-size: 10pt; }
</style>
<title>hr</title>
</head>
<?
extract
($HTTP_GET_VARS);
extract($HTTP_POST_VARS);
//$results_per_page - how many results you want to be displayed per page?
$results_per_page=5;
if(
$action == "search" && "list") {
$user file("site.dat");
$lis 0;
if(
strlen($keyword) <= 3){
    print 
"<p><BR><BR><BR><b>Tu palabra es demasiado corta, ha de tener como m&iacute;nimo tres letras.</b><br>";
}
else{
    for(
$x=0;$x<sizeof($user);$x++) {
        
$temp explode(";",$user[$x]);
        
$opp[$x] = "$temp[0];$temp[1];$temp[2];$temp[3]";
        
$such stristr($opp[$x],$keyword);
        if(
$such) { 
            
$list[$lis] = $opp[$x];
            
$lis++;
        }else{
            
$meta metaphone($keyword);
            
$meta2 metaphone($opp[$x]);
            
$such stristr($meta2,$meta);
            if(
$such) {
                
$list[$lis] = $opp[$x];
                
$lis++; 
            }
        }
    }
        function 
getmicrotime(){
        list(
$usec$sec) = explode(" ",microtime());
       return ((float)
$usec + (float)$sec);
    }

    
$time microtime(); 
    
$time number_format($time,3); 


    if(
sizeof($list) != "0") {
        
//sort($keyword);
        
echo "<font face=arial><p><b>",sizeof($list),"</b> Resultados encontrados de la palabra $keyword<BR>Tiempo de b&uacute;squeda $time segundos.</p></font>";
$fa fopen ("tempurl.txt""w");
fwrite ($fa"");
fclose ($fa);

for(
$y=0;$y<sizeof($list);$y++) {
$temp explode(";",$list[$y]);
$fa fopen ("tempurl.txt""a++");
fwrite ($fa$temp[0]);
fwrite ($fa";");
fwrite ($fa$temp[1]);
fwrite ($fa";");
fwrite ($fa$temp[2]);
fwrite ($fa";");
fwrite ($fa"\n");
fclose ($fa);
}
?>
<?
    
if (is_file("tempurl.txt"))
    {
    
$fp=file("tempurl.txt");
    
$s=sizeof($fp);
if (
$page=='' or !$page) { $page=1; }
$end=$results_per_page*$page;
$start=$end-$results_per_page;

if (
$start<>'0') {
    
$new_page=$page-1;
    
$prev="<a href='?action=list&page=$new_page'><---P&aacute;gina anterior</a>";
}
else {
    
$prev="";
}

if (
$end<$s) {
    
$new_page1=$page+1;
    
$next="<a href='?action=list&page=$new_page1'>P&aacutegina siguiente;---></a>";
}
else {
    
$next="";
}

for (
$i=$start$i<$end$i++)
    {
    
$p=explode(';'$fp[$i]);
echo 
"<dl><dd><font face=arial size=3><a href='$p[2]'><b>$p[0]</a></b><BR>$p[1]<BR><FONT SIZE=\"2\" COLOR=\"#00000\">$p[2]</FONT></dL>";
}
        }
    
$pages=$s/$results_per_page;
$pages1=round($pages2);
$pexplode("."$pages1);
$pcount=count($p);
$ext=$p[$pcount-2];
if (
$ext!=0) {
    
$num=$p[0]+1;
}

else {
    
$num=$p[0];
}
echo 
"<table width='100%'><tr><td align='left'>$prev</td><td align='center'>";
echo 
"";
    
for (
$i=1$i<=$num$i++) {
    if (
$i==$page) {
echo 
"<B>&nbsp;$i&nbsp;</B> ";

    }
    else {
echo 
"<a href='?action=list&page=$i'>[$i]</a>";
}
}
echo 
"</td><td align='right'>$next</td></table>";

}

else{
    echo 
"<p><b>Lo sentimos, no hay resultados en nuestra base de datos de la palabra $keyword.</b><br>";
    }
    }

}

if(
$action == "submit") {
$fp fopen ("site.dat""a+");
fwrite ($fp$title);
fwrite ($fp"*");
fwrite ($fp$description);
fwrite ($fp"*");
fwrite ($fp$link);
fwrite ($fp"*");
fwrite ($fp$keywords);
fwrite ($fp"*");
fwrite ($fp"\n");
fclose ($fp);
print 
"<pre><font face=arial size=3>Palabra añadida correctamente<br><br>";
    }
if(
$action == "add") {
echo 
" <center><font face=arial>Submit a site:</center><br></font><form name=\"add\" method=\"post\" action=\"?action=submit\">";
echo 
"<font face=arial size=2>Tltle:<FONT COLOR=\"#FF0066\">*</FONT><BR> <input type=text name=title size=30><br>The title of your site.</font><br><br>";
echo 
"<font face=arial size=2>Description:<FONT COLOR=\"#FF0066\">*</FONT> <BR><input type=text name=description size=50><br>Description of your site.</font><br><br>";
echo 
"<font face=arial size=2>Url:<FONT COLOR=\"#FF0066\">*</FONT><BR><input type=text name=link value=http:// size=30><br>Link of your site.</font><br><br>";
echo 
"<font face=arial size=2>Keywords:<FONT COLOR=\"#FF0066\">*</FONT><BR><input type=text name=keywords size=30><br>Seperate keywords by spaces</font><br><br><input type=submit value=Submit><BR><BR><FONT COLOR=\"#FF0066\">*</FONT>&nbsp;=&nbsp;Required</form>";
}
?>
<?php
if($action == "list" && "search") {
?>
<?

        
if (is_file("tempurl.txt"))
    {
    
$fp=file("tempurl.txt");
    
$s=sizeof($fp);

if (
$page=='' or !$page) { $page=1; }
$end=$results_per_page*$page;
$start=$end-$results_per_page;

if (
$start<>'0') {
    
$new_page=$page-1;
    
$prev="<a href='?action=list&page=$new_page'><---P&aacute;gina anterior</a>";
}
else {
    
$prev="";
}

if (
$end<$s) {
    
$new_page1=$page+1;
    
$next="<a href='?action=list&page=$new_page1'>P&aacute;gina siguiente---></a>";
}
else {
    
$next="";
}

for (
$i=$start$i<$end$i++)
    {
        
$p=explode(';'$fp[$i]);
echo 
"<dl><dd><font face=arial size=3><a href='$p[2]'><b>$p[0]</a></b><BR>$p[1]<BR><FONT SIZE=\"2\" COLOR=\"#00000\">$p[2]</FONT></dL>";
}
        }
    
$pages=$s/$results_per_page;
$pages1=round($pages2);
$p=explode('.'$pages1);
$pcount=count($p);
$ext=$p[$pcount-2];
if (
$ext!=0) {
    
$num=$p[0]+1;
}

else {
    
$num=$p[0];
}
echo 
"<table width='100%'><tr><td align='left'>$prev</td><td align='center'>";
echo 
"Page:";
for (
$i=1$i<=$num$i++) {
if (
$i==$page) {
echo 
"<B>&nbsp;$i&nbsp;</B>";
}
    else {
echo 
"<a href='?action=list&page=$i'>[$i]</a>";
}
}
echo 
"</td><td align='right'>$next</td></table>";

}
?>
</center>
</body>
</html></center>
 <body>
 <CENTER><form action="?action=search&list&page=1" method="post" name="searchform">
    <FONT SIZE="2"><img src="img/lupa.png" width="20" height="20" alt="lupa" /></FONT>
    <input type="text" name="keyword" size="20" maxlength="100">
            <input type="submit" value="Buscar"><BR><font size=2><BR>
    </form></CENTER>
    </body>
    </html>
  #2 (permalink)  
Antiguo 27/06/2011, 07:03
Avatar de iviamontes  
Fecha de Ingreso: enero-2011
Ubicación: $cubano->Arg->Mendoza
Mensajes: 1.184
Antigüedad: 13 años, 3 meses
Puntos: 209
Respuesta: Problemas con los caracteres

prueba utf8_decode / utf8_encode
  #3 (permalink)  
Antiguo 27/06/2011, 07:14
Avatar de thefranex3  
Fecha de Ingreso: junio-2011
Mensajes: 21
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: Problemas con los caracteres

No, no sirve :S

¿Alguna otra sugerencia?
  #4 (permalink)  
Antiguo 27/06/2011, 07:15
Avatar de iviamontes  
Fecha de Ingreso: enero-2011
Ubicación: $cubano->Arg->Mendoza
Mensajes: 1.184
Antigüedad: 13 años, 3 meses
Puntos: 209
Respuesta: Problemas con los caracteres

pudieras poner como lo probaste ??
  #5 (permalink)  
Antiguo 27/06/2011, 07:21
Avatar de thefranex3  
Fecha de Ingreso: junio-2011
Mensajes: 21
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: Problemas con los caracteres

Lo que hice fue cambiar utf-8 por utf8_decode y luego probar cambiandolo por utf8_encode.

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8_decode" />
<title>Buscador de Canarismos</title>
<html>
<head>
<style>
A:link          {text-decoration: none; color: #11116E;}
A:visited       {text-decoration: none; color: #11116E;}
A:hover          {font-style: normal; color: #000000; text-decoration: underline;}
BODY             {font-family: Verdana; font-size: 10pt; }
</style>
<title>hr</title>
</head>
<?
extract
($HTTP_GET_VARS);
extract($HTTP_POST_VARS);
//$results_per_page - how many results you want to be displayed per page?
$results_per_page=5;
if(
$action == "search" && "list") {
$user file("site.dat");
$lis 0;
if(
strlen($keyword) <= 3){
    print 
"<p><BR><BR><BR><b>Tu palabra es demasiado corta, ha de tener como m&iacute;nimo tres letras.</b><br>";
}
else{
    for(
$x=0;$x<sizeof($user);$x++) {
        
$temp explode(";",$user[$x]);
        
$opp[$x] = "$temp[0];$temp[1];$temp[2];$temp[3]";
        
$such stristr($opp[$x],$keyword);
        if(
$such) { 
            
$list[$lis] = $opp[$x];
            
$lis++;
        }else{
            
$meta metaphone($keyword);
            
$meta2 metaphone($opp[$x]);
            
$such stristr($meta2,$meta);
            if(
$such) {
                
$list[$lis] = $opp[$x];
                
$lis++; 
            }
        }
    }
        function 
getmicrotime(){
        list(
$usec$sec) = explode(" ",microtime());
       return ((float)
$usec + (float)$sec);
    }

    
$time microtime(); 
    
$time number_format($time,3); 


    if(
sizeof($list) != "0") {
        
//sort($keyword);
        
echo "<font face=arial><p><b>",sizeof($list),"</b> Resultados encontrados de la palabra $keyword<BR>Tiempo de b&uacute;squeda $time segundos.</p></font>";
$fa fopen ("tempurl.txt""w");
fwrite ($fa"");
fclose ($fa);

for(
$y=0;$y<sizeof($list);$y++) {
$temp explode(";",$list[$y]);
$fa fopen ("tempurl.txt""a++");
fwrite ($fa$temp[0]);
fwrite ($fa";");
fwrite ($fa$temp[1]);
fwrite ($fa";");
fwrite ($fa$temp[2]);
fwrite ($fa";");
fwrite ($fa"\n");
fclose ($fa);
}
?>
<?
    
if (is_file("tempurl.txt"))
    {
    
$fp=file("tempurl.txt");
    
$s=sizeof($fp);
if (
$page=='' or !$page) { $page=1; }
$end=$results_per_page*$page;
$start=$end-$results_per_page;

if (
$start<>'0') {
    
$new_page=$page-1;
    
$prev="<a href='?action=list&page=$new_page'><---P&aacute;gina anterior</a>";
}
else {
    
$prev="";
}

if (
$end<$s) {
    
$new_page1=$page+1;
    
$next="<a href='?action=list&page=$new_page1'>P&aacutegina siguiente;---></a>";
}
else {
    
$next="";
}

for (
$i=$start$i<$end$i++)
    {
    
$p=explode(';'$fp[$i]);
echo 
"<dl><dd><font face=arial size=3><a href='$p[2]'><b>$p[0]</a></b><BR>$p[1]<BR><FONT SIZE=\"2\" COLOR=\"#00000\">$p[2]</FONT></dL>";
}
        }
    
$pages=$s/$results_per_page;
$pages1=round($pages2);
$pexplode("."$pages1);
$pcount=count($p);
$ext=$p[$pcount-2];
if (
$ext!=0) {
    
$num=$p[0]+1;
}

else {
    
$num=$p[0];
}
echo 
"<table width='100%'><tr><td align='left'>$prev</td><td align='center'>";
echo 
"";
    
for (
$i=1$i<=$num$i++) {
    if (
$i==$page) {
echo 
"<B>&nbsp;$i&nbsp;</B> ";

    }
    else {
echo 
"<a href='?action=list&page=$i'>[$i]</a>";
}
}
echo 
"</td><td align='right'>$next</td></table>";

}

else{
    echo 
"<p><b>Lo sentimos, no hay resultados en nuestra base de datos de la palabra $keyword.</b><br>";
    }
    }

}

if(
$action == "submit") {
$fp fopen ("site.dat""a+");
fwrite ($fp$title);
fwrite ($fp"*");
fwrite ($fp$description);
fwrite ($fp"*");
fwrite ($fp$link);
fwrite ($fp"*");
fwrite ($fp$keywords);
fwrite ($fp"*");
fwrite ($fp"\n");
fclose ($fp);
print 
"<pre><font face=arial size=3>Palabra añadida correctamente<br><br>";
    }
if(
$action == "add") {
echo 
" <center><font face=arial>Submit a site:</center><br></font><form name=\"add\" method=\"post\" action=\"?action=submit\">";
echo 
"<font face=arial size=2>Tltle:<FONT COLOR=\"#FF0066\">*</FONT><BR> <input type=text name=title size=30><br>The title of your site.</font><br><br>";
echo 
"<font face=arial size=2>Description:<FONT COLOR=\"#FF0066\">*</FONT> <BR><input type=text name=description size=50><br>Description of your site.</font><br><br>";
echo 
"<font face=arial size=2>Url:<FONT COLOR=\"#FF0066\">*</FONT><BR><input type=text name=link value=http:// size=30><br>Link of your site.</font><br><br>";
echo 
"<font face=arial size=2>Keywords:<FONT COLOR=\"#FF0066\">*</FONT><BR><input type=text name=keywords size=30><br>Seperate keywords by spaces</font><br><br><input type=submit value=Submit><BR><BR><FONT COLOR=\"#FF0066\">*</FONT>&nbsp;=&nbsp;Required</form>";
}
?>
<?php
if($action == "list" && "search") {
?>
<?

        
if (is_file("tempurl.txt"))
    {
    
$fp=file("tempurl.txt");
    
$s=sizeof($fp);

if (
$page=='' or !$page) { $page=1; }
$end=$results_per_page*$page;
$start=$end-$results_per_page;

if (
$start<>'0') {
    
$new_page=$page-1;
    
$prev="<a href='?action=list&page=$new_page'><---P&aacute;gina anterior</a>";
}
else {
    
$prev="";
}

if (
$end<$s) {
    
$new_page1=$page+1;
    
$next="<a href='?action=list&page=$new_page1'>P&aacute;gina siguiente---></a>";
}
else {
    
$next="";
}

for (
$i=$start$i<$end$i++)
    {
        
$p=explode(';'$fp[$i]);
echo 
"<dl><dd><font face=arial size=3><a href='$p[2]'><b>$p[0]</a></b><BR>$p[1]<BR><FONT SIZE=\"2\" COLOR=\"#00000\">$p[2]</FONT></dL>";
}
        }
    
$pages=$s/$results_per_page;
$pages1=round($pages2);
$p=explode('.'$pages1);
$pcount=count($p);
$ext=$p[$pcount-2];
if (
$ext!=0) {
    
$num=$p[0]+1;
}

else {
    
$num=$p[0];
}
echo 
"<table width='100%'><tr><td align='left'>$prev</td><td align='center'>";
echo 
"Page:";
for (
$i=1$i<=$num$i++) {
if (
$i==$page) {
echo 
"<B>&nbsp;$i&nbsp;</B>";
}
    else {
echo 
"<a href='?action=list&page=$i'>[$i]</a>";
}
}
echo 
"</td><td align='right'>$next</td></table>";

}
?>
</center>
</body>
</html></center>
 <body>
 <CENTER><form action="?action=search&list&page=1" method="post" name="searchform">
    <FONT SIZE="2"><img src="img/lupa.png" width="20" height="20" alt="lupa" /></FONT>
    <input type="text" name="keyword" size="20" maxlength="100">
            <input type="submit" value="Buscar"><BR><font size=2><BR>
    </form></CENTER>
    </body>
    </html>
  #6 (permalink)  
Antiguo 27/06/2011, 07:30
Avatar de iviamontes  
Fecha de Ingreso: enero-2011
Ubicación: $cubano->Arg->Mendoza
Mensajes: 1.184
Antigüedad: 13 años, 3 meses
Puntos: 209
Respuesta: Problemas con los caracteres

no amigo, uft8-encode() es una funcion php

se usa así

<?php echo utf8_encode("ñññññññññññññ"); ?>
  #7 (permalink)  
Antiguo 27/06/2011, 07:39
Avatar de thefranex3  
Fecha de Ingreso: junio-2011
Mensajes: 21
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: Problemas con los caracteres

Perdona por mi ignorancia, solo programa html, pero al tener que hacer una barra de búsqueda,...

Me informo por internet, y ya no molesto más ;)
  #8 (permalink)  
Antiguo 27/06/2011, 07:43
Avatar de iviamontes  
Fecha de Ingreso: enero-2011
Ubicación: $cubano->Arg->Mendoza
Mensajes: 1.184
Antigüedad: 13 años, 3 meses
Puntos: 209
Respuesta: Problemas con los caracteres

aca estamos para ayudarnos, no hay nada que disculpar, busca acá
http://php.net/manual/es/function.utf8-encode.php
otra cosa, los tags php no los abras asi <?, mejor es así <?php
  #9 (permalink)  
Antiguo 27/06/2011, 07:43
Avatar de thefranex3  
Fecha de Ingreso: junio-2011
Mensajes: 21
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: Problemas con los caracteres

La verdad, no sabría hacerlo, ¿Puedes echarme una mano?
  #10 (permalink)  
Antiguo 27/06/2011, 07:48
Avatar de thefranex3  
Fecha de Ingreso: junio-2011
Mensajes: 21
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: Problemas con los caracteres

Bueno, he estado viendo este código:

Código PHP:
echo utf8_encode("Mañanas de programación PHP"); 
Pero mi problema es que mi buscador está dividido en varios archivos, el primero es el que posteé al principio, es la barra de búsqueda, el segundo es una pequeña base de datos (Un archivo con extensión .dat) donde están principalmente todas las tildes, y no está en php, y por último un archivo temporal...

Etiquetas: caracteres, interrogante, simbolo, tildes
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 19:10.