IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Pb d'accents sur date


Sujet :

Langage PHP

  1. #1
    Membre éclairé Avatar de Casio
    Homme Profil pro
    Historien numérique
    Inscrit en
    Novembre 2005
    Messages
    312
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Historien numérique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 312
    Par défaut Pb d'accents sur date
    Salutations,

    J'utilise depuis des années un forum phpBB.
    J'utilise aussi un script qui me permet d'avoir les x derniers posts du forum sur notre home.

    Tout marche nickel, sauf que je n'arrive pas à corriger des pbs d'affichage de date contenant des les mois avec accents ( Août, Février, etc..)

    En effet, il me traduit cela par "Aoû" au lieu de Aoû"...
    J'ai essayé un peu dans tous les sens... format_date, utf8_decode, etc... Nada...

    Voici le bout de code intéressant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    (...)
        while($row = $db->sql_fetchrow($result))
        {
            $row['topic_title'] = utf8_decode($row['topic_title']);
            $row['topic_first_poster_name'] = utf8_decode($row['topic_first_poster_name']);
            $row['topic_last_poster_name'] = utf8_decode($row['topic_last_poster_name']);
    		$row['topic_time'] = utf8_decode($row['topic_time']);
            $topic_id = $row['topic_id'];
            $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . '&t=' . $topic_id);
            //$row_colour = ($i % 2) ? '#FFFFCC' : '#99FFFF';
            //echo '<tr bgcolor="' . $row_colour .'">';
            echo '<tr>';
            echo '<td align="left">';
            echo '<a href="' . $view_topic_url . '">' . censor_text($row['topic_title']) . '</a><br />';
            echo $user->lang['POST_BY_AUTHOR'] . '&nbsp;' . get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']);
            echo '&nbsp;' . $user->lang['POSTED_ON_DATE'] . '&nbsp;' . $user->format_date($row['topic_time']) . '</td>';
            echo '<td align="center">' . $row['topic_replies'] . '</td>';
            echo '<td align="center">' . $row['topic_views'] . '</td>';
            echo '<td align="left">' . $user->lang['POST_BY_AUTHOR'] . '&nbsp;' . get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']);
            echo '&nbsp;<a href="' . $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'] . '"><img src="' . $phpbb_root_path . 'styles/' . $user->theme['imageset_path'] . '/imageset/icon_topic_latest.gif" border="0" alt="' . $user->lang['VIEW_LATEST_POST'] . '" title="' . $user->lang['VIEW_LATEST_POST'] . '" />' . '</a><br />';
            echo $user->lang['POSTED_ON_DATE'] . '&nbsp;' . $user->format_date($row['topic_last_post_time']) . '</td>';
            echo '</tr>';
            $i++;
        }
    (...)
    C'est au niveau de "echo '&nbsp;' . $user->lang['POSTED_ON_DATE'] . '&nbsp;' . $user->format_date($row['topic_time']) . '</td>';"

    Any idea ?

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Il faut controler
    - l'encodage de la table
    - l'encodage du fichier PHP (notepad++ donne cette information)
    - l'encodage de la page HTML.

    Déjà puisqu'il y a des utf8_decode() sur les autres données, c'est qu'a priori la page HTML est en ISO alors que la table est en UTF8.
    Le type d'affichage que tu obtiens correspond d'ailleurs à un caractère UTF8 affiché dans une page ISO. utf8_decode() devrait donc egalement faire l'affaire.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Membre très actif Avatar de metagoto
    Profil pro
    Hobbyist programmateur
    Inscrit en
    Juin 2009
    Messages
    646
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Hobbyist programmateur

    Informations forums :
    Inscription : Juin 2009
    Messages : 646
    Par défaut
    Effectivement, il "manquerait" un utf8_decode sur $row['topic_last_post_time']

    Je ne sais pas quel niveau de contrôle tu as sur tout ça, mais il me paraîtrait bien plus judicieux d'avoir une page servie en utf-8, et donc virer tous les utf8_decode, mettre un charset=utf-8 dans le header content-type et ajuster le <meta> du html...

  4. #4
    Membre éclairé Avatar de Casio
    Homme Profil pro
    Historien numérique
    Inscrit en
    Novembre 2005
    Messages
    312
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Historien numérique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 312
    Par défaut
    Il s'agit d'un fichier PHP en include dans une arbo. CSS/PHP.
    Celle-ci affiche une table contenant les 5 derniers posts de nos forums phpBB 3.

    Voici le code entier de cette page PHP :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    <table width="600" border="0" bgcolor="#FFFFFF" STYLE="background-image: url(pict/Cadre1-fond.gif); background-repeat: no-repeat; background-position: center">
    <tr>
        <td align="left" class="atype2">
     
    	<?php 
        $auth->acl($user->data);
        $user->setup();
        $forum_id = request_var('forum_id', 0);
        $where = ($forum_id) ? "WHERE forum_id=$forum_id" : '';
        $sql = 'SELECT forum_id, topic_id, topic_time, topic_title, topic_views, topic_replies, topic_poster, topic_first_poster_name, topic_first_poster_colour, topic_last_post_id, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour, topic_last_post_time FROM ' . TOPICS_TABLE . $where . ' ORDER BY topic_last_post_time DESC ' . ' LIMIT 0 , 5 ';
        $result = $db->sql_query($sql);
     
        echo '<table width="100%" class="newsforum">';
     
        echo '<tr>';
        echo '<th align="left">Sujets</th>';
        echo '<th align="center">Réponses</th>';
        echo '<th align="center">Vus</th>';
        echo '<th align="right">Dernier message</th>';
        echo '</tr>';
     
        $i=0;
        while($row = $db->sql_fetchrow($result))
        {
            $row['topic_title'] = utf8_decode($row['topic_title']);
            $row['topic_first_poster_name'] = utf8_decode($row['topic_first_poster_name']);
            $row['topic_last_poster_name'] = utf8_decode($row['topic_last_poster_name']);
    		$row['topic_time'] = utf8_decode($row['topic_time']);
            $topic_id = $row['topic_id'];
            $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . '&amp;t=' . $topic_id);
            //$row_colour = ($i % 2) ? '#FFFFCC' : '#99FFFF';
            //echo '<tr bgcolor="' . $row_colour .'">';
            echo '<tr>';
            echo '<td align="left">';
            echo '<a href="' . $view_topic_url . '">' . censor_text($row['topic_title']) . '</a><br />';
            echo $user->lang['POST_BY_AUTHOR'] . '&nbsp;' . get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']);
            echo '&nbsp;' . $user->lang['POSTED_ON_DATE'] . '&nbsp;' . $user->format_date($row['topic_time']) . '</td>';
            echo '<td align="center">' . $row['topic_replies'] . '</td>';
            echo '<td align="center">' . $row['topic_views'] . '</td>';
            echo '<td align="left">' . $user->lang['POST_BY_AUTHOR'] . '&nbsp;' . get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']);
            echo '&nbsp;<a href="' . $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'] . '"><img src="' . $phpbb_root_path . 'styles/' . $user->theme['imageset_path'] . '/imageset/icon_topic_latest.gif" border="0" alt="' . $user->lang['VIEW_LATEST_POST'] . '" title="' . $user->lang['VIEW_LATEST_POST'] . '" />' . '</a><br />';
            echo $user->lang['POSTED_ON_DATE'] . '&nbsp;' . $user->format_date($row['topic_last_post_time']) . '</td>';
            echo '</tr>';
            $i++;
        }
     
        echo '</table>';
        ?>
     
    	</td>
    </tr>
    </table>

  5. #5
    Membre très actif Avatar de metagoto
    Profil pro
    Hobbyist programmateur
    Inscrit en
    Juin 2009
    Messages
    646
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Hobbyist programmateur

    Informations forums :
    Inscription : Juin 2009
    Messages : 646
    Par défaut
    Comme on a dit:

    Dans le code, tu as quelque part pas loin en dessous du while() :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $row['topic_time'] = utf8_decode($row['topic_time']);
    Et bien il faut faire pareil pour $row['topic_last_post_time']. Rajoute une ligne. Ca donnera:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $row['topic_time'] = utf8_decode($row['topic_time']);
    $row['topic_last_post_time'] = utf8_decode($row['topic_last_post_time']); // ajouté

  6. #6
    Membre éclairé Avatar de Casio
    Homme Profil pro
    Historien numérique
    Inscrit en
    Novembre 2005
    Messages
    312
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Historien numérique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 312
    Par défaut
    Merci, mais malheureusement, cela ne change rien... Il s'agit bien de la variable 'topic_time' et non 'topic_last_post_time'.
    Je viens de re-tester...

    L'echo qui affiche cette partie est $user->format_date($row['topic_time'])...

  7. #7
    Membre très actif Avatar de metagoto
    Profil pro
    Hobbyist programmateur
    Inscrit en
    Juin 2009
    Messages
    646
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Hobbyist programmateur

    Informations forums :
    Inscription : Juin 2009
    Messages : 646
    Par défaut
    A oui, désolé. Sur ton site (je suppose qu'il s'agit de celui-là), je n'avais pas fait gaffe que les dates déconnent des 2 cotés du tableau (posts et derniers posts).

    De toute façon, $row['topic_time'] et son acolyte sont probablement des types timestamp ou quoi qu'il en soit, non affectés par utf8.

    La seule solution que je vois pour fixer ça sans changer les choses radicalement (voir mon premier post), est de mettre les fameux utf8_decode() autour des $user->format_date(). Donc aux deux endroits où tu as ce format_date, tu mets (ici, juste l'exemple pour le premier) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    utf8_decode($user->format_date($row['topic_time']))
    ce qui m'inquiète c'est que tu as probablement testé ça déja...

  8. #8
    Membre éclairé Avatar de Casio
    Homme Profil pro
    Historien numérique
    Inscrit en
    Novembre 2005
    Messages
    312
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Historien numérique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 312
    Par défaut
    YES !

    Pb de typo. ou de syntaxe, certainement, j'avais essayé, mais pas persévéré...

    Cela donne donc le code suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    	<?php 
        $auth->acl($user->data);
        $user->setup();
        $forum_id = request_var('forum_id', 0);
        $where = ($forum_id) ? "WHERE forum_id=$forum_id" : '';
        $sql = 'SELECT forum_id, topic_id, topic_time, topic_title, topic_views, topic_replies, topic_poster, topic_first_poster_name, topic_first_poster_colour, topic_last_post_id, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour, topic_last_post_time FROM ' . TOPICS_TABLE . $where . ' ORDER BY topic_last_post_time DESC ' . ' LIMIT 0 , 5 ';
        $result = $db->sql_query($sql);
     
        echo '<table width="100%" class="newsforum">';
     
        echo '<tr>';
        echo '<th align="left">Sujets</th>';
        echo '<th align="center">Réponses</th>';
        echo '<th align="center">Vus</th>';
        echo '<th align="right">Dernier message</th>';
        echo '</tr>';
     
        $i=0;
        while($row = $db->sql_fetchrow($result))
        {
            $row['topic_title'] = utf8_decode($row['topic_title']);
            $row['topic_first_poster_name'] = utf8_decode($row['topic_first_poster_name']);
            $row['topic_last_poster_name'] = utf8_decode($row['topic_last_poster_name']);
    		$row['topic_time'] = utf8_decode($row['topic_time']);
    		$row['topic_last_post_time'] = utf8_decode($row['topic_last_post_time']); // ajouté
            $topic_id = $row['topic_id'];
            $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . '&amp;t=' . $topic_id);
            //$row_colour = ($i % 2) ? '#FFFFCC' : '#99FFFF';
            //echo '<tr bgcolor="' . $row_colour .'">';
            echo '<tr>';
            echo '<td align="left">';
            echo '<a href="' . $view_topic_url . '">' . censor_text($row['topic_title']) . '</a><br />';
            echo $user->lang['POST_BY_AUTHOR'] . '&nbsp;' . get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']);
            echo '&nbsp;' . $user->lang['POSTED_ON_DATE'] . '&nbsp;' . utf8_decode($user->format_date($row['topic_time'])) . '</td>';
            echo '<td align="center">' . $row['topic_replies'] . '</td>';
            echo '<td align="center">' . $row['topic_views'] . '</td>';
            echo '<td align="left">' . $user->lang['POST_BY_AUTHOR'] . '&nbsp;' . get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']);
            echo '&nbsp;<a href="' . $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'] . '"><img src="' . $phpbb_root_path . 'styles/' . $user->theme['imageset_path'] . '/imageset/icon_topic_latest.gif" border="0" alt="' . $user->lang['VIEW_LATEST_POST'] . '" title="' . $user->lang['VIEW_LATEST_POST'] . '" />' . '</a><br />';
            echo $user->lang['POSTED_ON_DATE'] . '&nbsp;' . utf8_decode($user->format_date($row['topic_last_post_time'])) . '</td>';
            echo '</tr>';
            $i++;
        }
     
        echo '</table>';
        ?>
    Et cela fonctionne... ;-)

    Merci à tous

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [CR] pb (concaténation/Conversion/Addition) sur date/heure
    Par marvel dans le forum SAP Crystal Reports
    Réponses: 1
    Dernier message: 20/12/2004, 15h31
  2. Requête sur date
    Par guenfood dans le forum Access
    Réponses: 11
    Dernier message: 08/12/2004, 16h11
  3. [Debutant(e)]operation sur dates
    Par sUrTr dans le forum Collection et Stream
    Réponses: 2
    Dernier message: 11/10/2004, 15h58
  4. Resutlat de calcul sur date formaté
    Par neness dans le forum SQL
    Réponses: 6
    Dernier message: 16/06/2004, 15h34
  5. Calcul sur date
    Par Thomad dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 17/09/2003, 08h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo