Foros del Web » Programando para Internet » PHP »

carácteres raros

Estas en el tema de carácteres raros en el foro de PHP en Foros del Web. carácteres "raros" en un sistema que ando modificando. Ayer hablé sobre un sistemilla de blogs y demás que tuve problema,le di de lado y ahora ...
  #1 (permalink)  
Antiguo 12/08/2010, 14:04
Avatar de falillista  
Fecha de Ingreso: agosto-2008
Mensajes: 101
Antigüedad: 15 años, 7 meses
Puntos: 4
carácteres raros

carácteres "raros" en un sistema que ando modificando.

Ayer hablé sobre un sistemilla de blogs y demás que tuve problema,le di de lado y ahora encontré otro.Lo ando modificando.Lo tengo la listo todo,pero me salen carácteres raros al crear un post.Un ejemplo:

http://www.subirimagenes.com/imagen-12s-4964842.html

la bd está así:


Tengo por ejemplo la plantilla de los posts separado como "plantilla_posteo.php"

Código PHP:
<div class="post" id="post-$postid$">
    <
h2><img src=$imgruta$/noticias.png> - <a href="$posturl$">$posttitle$</a></h2>
        <
br>
    <
div class="post-content">
        
$postcontent$    
    </
div>
        <
br>
    <
span class="date">($postdate$) - <b>Posteado por:</b$posteado$</span><br>
        <
hr>
</
div
Código:
-- phpMyAdmin SQL Dump
-- version 3.2.4
-- http://www.phpmyadmin.net
--
-- Servidor: localhost
-- Tiempo de generación: 12-08-2010 a las 17:31:05
-- Versión del servidor: 5.0.91
-- Versión de PHP: 5.2.6

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Base de datos: `rafaj695_portal`
--

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `entradas`
--

CREATE TABLE IF NOT EXISTS `entradas` (
  `post_id` int(20) NOT NULL auto_increment,
  `post_slug` varchar(255) NOT NULL default '',
  `post_title` varchar(255) NOT NULL default '',
  `post_content` longtext NOT NULL,
  `date` int(20) NOT NULL default '0',
  `published` int(1) NOT NULL default '0',
  PRIMARY KEY  (`post_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Volcar la base de datos para la tabla `entradas`
--

INSERT INTO `miniblog` (`post_id`, `post_slug`, `post_title`, `post_content`, `date`, `published`) VALUES
(1, 'bienvenidos-a-pdh-', '¡Bienvenidos a PDH! ;)', '<p>Bienvenidos a PDH... y al portal...desde aquí se actualizará todo.</p>', 1281644373, 1);

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `config_web`
--

CREATE TABLE IF NOT EXISTS `miniblog_config` (
  `config_name` varchar(255) NOT NULL default '',
  `config_value` varchar(255) NOT NULL default '',
  `config_explain` longtext NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Volcar la base de datos para la tabla `config_web`
--

INSERT INTO `config_web` (`config_name`, `config_value`, `config_explain`) VALUES
('posts-per-page', '5', 'Posts displayed each page'),
('date-format', 'F d, Y', 'Date format as per the PHP date function <a href="http://www.php.net/date">here</a>'),
('password', '-->ESTA ZONA ES LA PW,EN MD5', 'Admin password'),
('miniblog-filename', 'index.php', 'Name of the file which miniblog.php is included into'),
('use-modrewrite', '0', 'Use modrewrite for post URLs - use 1 for yes, 0 for no.');
=>

y este el archivo sistema.php:

Código PHP:
<?php
if(!defined('IN_BLOG'))
{
    exit;
}

include(
PATH "$sistema/includes/config.php");
include(
PATH "$sistema/includes/functions.php");

$link mb_connect($sqlconfig);
unset(
$sqlconfig);

if(!
$link)
{
    die(
"Could not connect to MySQL database, check the settings in config.php");
}

$config mb_config();

$post    = (string) mysql_real_escape_string($_GET['post']);
$page    = (int) mysql_real_escape_string(intval($_GET['page']));
$ppp    = (int) intval($config['posts-per-page']);
$from    = (int) intval($ppp $page);


$sql = ($post == '') ? 'SELECT * FROM `miniblog` WHERE `published` = 1 ORDER BY `date` DESC LIMIT ' $from ', ' $ppp "SELECT * FROM `miniblog` WHERE `post_slug` = '{$post}' AND `published` = 1";

$result mysql_query($sql);
$total  mysql_result(mysql_query("SELECT COUNT(*) FROM `miniblog` WHERE `published` = 1"), 0);

if(
mysql_num_rows($result) > 0)

    while(
$posts mysql_fetch_array($result))
    {

        
$vars = array(
            
'$postid$'        => $posts['post_id'],
            
'$posturl$'        => ($config['use-modrewrite'] == 1) ? $posts['post_slug'] : $config['miniblog-filename'] . '?post=' $posts['post_slug'],
            
'$posttitle$'    => stripslashes($posts['post_title']),
            
'$postdate$'    => date($config['date-format'], $posts['date']),
            
'$postcontent$'    => stripslashes($posts['post_content']),
            
'$posteado$'    => stripslashes($posteadopor),
            
'$imgruta$'    => stripslashes($img_rute),
        );
        
        
$template_vars        array_keys($vars);
        
$template_values    array_values($vars);
        
        
$output file_get_contents(PATH "$sistema/includes/plantilla_posteo.php");
        
$output str_replace($template_vars$template_values$output);
        
        
$miniblog_posts .= $output;
    }
}

$single = ($post == '') ? false true;

if(
$total > ($from $ppp))
{
    
$miniblog_previous '<a href="' $config['miniblog-filename'] . '?page=' . ($page 1)  . '">&laquo; Antiguos posts</a>';
}
if(
$from 0)
{
    
$miniblog_next '<a href="' $config['miniblog-filename'] . '?page=' . ($page 1)  . '">Posts m&aacute;s nuevos &raquo;</a>';
}
?>
El archivo contenido.php:

Código PHP:
<?php
define
('IN_BLOG'true);
define('PATH''');
include(
"$sistema/includes/sistema.php");
?>

<?=$miniblog_posts?>
<? 
if(!$single) { ?>
<? 
if($miniblog_previous) {    ?> <p class="previous-link"><?=$miniblog_previous?></p>    <? ?>
<? 
if($miniblog_next) {    ?>    <p class="next-link"><?=$miniblog_next?></p> <? ?>
<? 
?>
<? 
if($single) { ?>
<p class="previous-link"><a href="<?=$config['miniblog-filename']?>">&laquo; volver a los posts</a></p>
<? ?>
<div class="clear"></div>
y el index.php donde con un include,lo incluyo en la página principal.

Código PHP:
<?php
/**************************
 * Portal by PDH v1 ;)
 **************************/
include("configurar.php"); ?>

<title><? echo $nombre ?></title>

<?php include("$ruta/arriba.php"); ?>

<!--- CONTENIDO --->
<div id="pdh">
<div id="pdh2">
<div class="pdh3">

<?php include("$sistema/contenido.php"); ?>

</div></div>
<!--- FIN CONTENIDO --->

<?php include("$ruta/abajo.php"); ?>
</body>
el sistema es Miniblog,solo que le edité cosas,lo puse sobretodo a mi gusto,para adaptarlo a cualquier plantilla,o sitio.

si alguien me sabe responder,se lo agradeceré...

pd esos archivos son PRINCIPALES,los que muestran los posts.
  #2 (permalink)  
Antiguo 12/08/2010, 14:09
 
Fecha de Ingreso: marzo-2010
Mensajes: 17
Antigüedad: 14 años, 1 mes
Puntos: 0
Respuesta: carácteres raros

Podrias probar con las funciones de PHP que se llaman htmlspecialchars (y todos su derivados), quizás te es más conveniente guardar el código de la letra o caracter que tenga el acento o un "simbolo raro".

Cuéntame cómo te va.
  #3 (permalink)  
Antiguo 12/08/2010, 15:58
Avatar de falillista  
Fecha de Ingreso: agosto-2008
Mensajes: 101
Antigüedad: 15 años, 7 meses
Puntos: 4
Respuesta: carácteres raros

probé eso y quedó así:

<div class="post" id="post-1"> <h2><img src=imagenes/noticias.png> - <b>�Bienvenidos a PDH! ;)</b></h2> <br> <div class="post-content"> <p>Bienvenidos a PDH... y al portal...desde aqu� se actualizar� todo.</p> </div> <br> <span class="date">(August 12, 2010) - <b>Posteado por:</b> AWES0MN <br><br><a href=index.php?post=bienvenidos-a-pdh->>>Leer m&aacute;s...</a></span><br> <hr> </div>

Código PHP:
<?php $new htmlspecialchars("$miniblog_posts"ENT_QUOTES); ?>
<?=$new?>
  #4 (permalink)  
Antiguo 12/08/2010, 16:12
Avatar de falillista  
Fecha de Ingreso: agosto-2008
Mensajes: 101
Antigüedad: 15 años, 7 meses
Puntos: 4
Respuesta: carácteres raros

por cierto,es raro,donde está la parte del post, e puesto un echo (borrando todo)

así: "echo "ááá";" y a ido bien... :|
  #5 (permalink)  
Antiguo 12/08/2010, 16:24
Avatar de chulifo  
Fecha de Ingreso: abril-2009
Ubicación: perdido en codigos del PHP, pero aprendo rapido!
Mensajes: 524
Antigüedad: 15 años
Puntos: 18
Respuesta: carácteres raros

y si pruebas asi ?

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
__________________
Solo soy un simple fanático que mata el tiempo de la mejor manera.
  #6 (permalink)  
Antiguo 12/08/2010, 16:26
Avatar de falillista  
Fecha de Ingreso: agosto-2008
Mensajes: 101
Antigüedad: 15 años, 7 meses
Puntos: 4
Respuesta: carácteres raros

eso lo probé y nada, de hecho tengo un header.php y tiene todo en regla los utf-8 y demás.
  #7 (permalink)  
Antiguo 12/08/2010, 16:27
Avatar de silvanha  
Fecha de Ingreso: marzo-2006
Ubicación: En mi mundo de sueños
Mensajes: 653
Antigüedad: 18 años, 1 mes
Puntos: 65
Respuesta: carácteres raros

mandar a imprimir con htmlentities() también sirve.. intentalo =)
__________________
●•· No hay nada imposible..
●•· Vico-X.. ;)
  #8 (permalink)  
Antiguo 12/08/2010, 16:28
Avatar de falillista  
Fecha de Ingreso: agosto-2008
Mensajes: 101
Antigüedad: 15 años, 7 meses
Puntos: 4
Respuesta: carácteres raros

perdón por expresión pero... "joer"

solo necesitaba poner:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

en el header,realmente el iso-8859-1 me a salvado con otros scripts,lo usaré siempre por ahora ;P
  #9 (permalink)  
Antiguo 12/08/2010, 16:30
 
Fecha de Ingreso: agosto-2010
Ubicación: Tenerife
Mensajes: 893
Antigüedad: 13 años, 8 meses
Puntos: 202
Respuesta: carácteres raros

tbn podría servirte quizás:

Código PHP:
<?php
//EJEMPLO:

$str='¡Bienvenidos a PDH... y al portal... desde aquí se actualizará todo!';

echo 
$str.'<br><br>'//Original, saldría en tu caso: Â¡Bienvenidos a PDH... y al portal... desde aquÃ* se actualizará todo!
echo mb_convert_encoding($str"ISO-8859-1""UTF-8"); //pasando a UTF-8

?>
Un Saludo.
  #10 (permalink)  
Antiguo 12/08/2010, 16:37
Avatar de falillista  
Fecha de Ingreso: agosto-2008
Mensajes: 101
Antigüedad: 15 años, 7 meses
Puntos: 4
Respuesta: carácteres raros

gracias IEEK,lo malo que es mysql.Supongo que donde dice $str podría meter la variable de los posts,ni idea.Tampoco después de todo podré probarlo.Bueno gracias y saludos :D
  #11 (permalink)  
Antiguo 12/08/2010, 22:40
Avatar de truman_truman  
Fecha de Ingreso: febrero-2010
Ubicación: /home/user
Mensajes: 1.341
Antigüedad: 14 años, 2 meses
Puntos: 177
Respuesta: carácteres raros

Probá poniendo esto justo abajo de la consulta

Código PHP:
mysql_query("SET NAMES 'utf8'"); 
__________________
la la la

Etiquetas: raros
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 15:34.