Foros del Web » Programando para Internet » PHP »

Problemas caracteres urf8

Estas en el tema de Problemas caracteres urf8 en el foro de PHP en Foros del Web. Verán lo típico, que no se me ven los carácteres en php: Normalmente lo soluciono con esto: Código PHP: < meta http - equiv = "Content-Type"  ...
  #1 (permalink)  
Antiguo 24/06/2011, 04:10
Avatar de thefranex3  
Fecha de Ingreso: junio-2011
Mensajes: 21
Antigüedad: 12 años, 9 meses
Puntos: 0
Pregunta Problemas caracteres urf8

Verán lo típico, que no se me ven los carácteres en php:



Normalmente lo soluciono con esto:

Código PHP:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
Pero esta vez estoy usando un script, con lo que al modificarlo no me acepta.

Este es el script:

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>Your keyword must be longer than 3 characters</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> Search Result(s) Found For $keyword<BR>Search took $time Seconds.</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'><---Previous page</a>";
}
else {
    
$prev="";
}

if (
$end<$s) {
    
$new_page1=$page+1;
    
$next="<a href='?action=list&page=$new_page1'>Next page---></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 
"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>";

}

else{
    echo 
"<p><b>Sorry but we could not find any results for $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>Site has been added successfully<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'><---Previous page</a>";
}
else {
    
$prev="";
}

if (
$end<$s) {
    
$new_page1=$page+1;
    
$next="<a href='?action=list&page=$new_page1'>Next page---></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">Search For:</FONT>
            <input type="text" name="keyword" size="20" maxlength="100">
            <input type="submit" value="Search"><BR><font size=2><BR>
    </form></CENTER>
    </body>
    </html>
Es un simple buscador, además está acompañado de un archivo temporal, y una base de datos en formato .dat, donde están todos los datos y donde están los caracteres especiales.

Alguien sabe alguna forma de solucionarlo, hace tiempo estaba buscando una lista de caracteres en utf8 convertidos a iso, pero no la encuentro :s
  #2 (permalink)  
Antiguo 24/06/2011, 04:44
 
Fecha de Ingreso: junio-2011
Mensajes: 4
Antigüedad: 12 años, 9 meses
Puntos: 0
Respuesta: Problemas caracteres urf8

Bueno, yo tengo un problema similar, pero suelo solucionarlo con una funcion que sustituye los caracters espaciales por su correspondiente en html en un texto que contiene el texto a mostra en pantalla, lo deja muy bien, pero tal como tienes el codigo, no se si te puede solucionar.
Te dejo una lista de los caracteres a ver si te sirve de algo.
[URL="http://www.desarrolloweb.com/articulos/11.php"]http://www.desarrolloweb.com/articulos/11.php[/URL]
  #3 (permalink)  
Antiguo 24/06/2011, 07:01
 
Fecha de Ingreso: marzo-2011
Ubicación: Caracas - Venezuela
Mensajes: 52
Antigüedad: 13 años, 1 mes
Puntos: 6
Respuesta: Problemas caracteres urf8

Te recomiendo que te pasees por este tema:

http://www.forosdelweb.com/f18/probl...8/#post3883028


Al comienzo de tu petición debes usar:

Código PHP:
header('Content-type: text/html; charset=utf-8'); 
Y mantén:

Código HTML:
Ver original
  1. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Además revisa que charset estas usando en tu base de datos, con que charset estan creadas las tablas... Deben ser UTF-8 también.

Emparejando todo a UTF-8 va de pelos. Eso ya me ha pasado a mi infinidad de veces.


Saludos.
__________________
Deja un pelo de karma si mi comentario fue de ayuda!!! ;)

Etiquetas: caracteres, iso, lista, utf-8
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 13:53.