Page 1 of 1

request_var and normalize_nfc

Posted: Fri Feb 18, 2011 4:17 pm
by hah
Hello, I have problem with request_var.If I use it with template everything is fine, but when don't use template (external pages) for that I can't get multibyte symbols to work.

I use - utf8_normalize_nfc(request_var('message', '', true)) and thats the correct using for multibyte.

$_POST['message'] == "asd"
after going through utf8_normalize & request_var
result
asd

$_POST['message'] == "асд"
after going through utf8_normalize & request_var
result

(nothing)

As I said with template its find, but without..
Actually I use the format_date for class user and the day names don't get in cyrillic, too.

Re: request_var and normalize_nfc

Posted: Fri Feb 18, 2011 9:15 pm
by 4_seven
try this in a php outside of phpbb3

Code: Select all

$post_message = $_POST['message']; // or $_GET ;)
$post_message = iconv("ISO-8859-1", "UTF-8", $post_message); 
also try this, if you want to transform from inside phpbb3 to outside

Code: Select all

$post_message = request_var('message', '', true);
$post_message = iconv("ISO-8859-1", "UTF-8", $post_message);   
or

Code: Select all

$post_message = utf8_normalize_nfc(request_var('message', '', true));
$post_message = iconv("ISO-8859-1", "UTF-8", $post_message);  

Re: request_var and normalize_nfc

Posted: Sun Feb 20, 2011 10:41 am
by hah
Well, no it doesn't work.Thats really awful..

Re: request_var and normalize_nfc

Posted: Sun Feb 20, 2011 3:05 pm
by 4_seven
well, for me it works in all cases with such construct.
i think, it's because we don't know how exactly your construct is build.

Re: request_var and normalize_nfc

Posted: Mon Feb 21, 2011 10:08 am
by AmigoJack
4_seven wrote:it's because we don't know how exactly your construct is build.
...and which encodings all of your files and forms do have.

Re: request_var and normalize_nfc

Posted: Mon Feb 21, 2011 6:12 pm
by 4_seven
AmigoJack wrote:
4_seven wrote:it's because we don't know how exactly your construct is build.
...and which encodings all of your files and forms do have.
yap, so it's wired..

Re: request_var and normalize_nfc

Posted: Tue Feb 22, 2011 9:35 am
by hah
Well, I'm telling you, non of this works I tried with several encoding's..

Here is the code

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
   
global $user, $db, $phpbb_root_path, $phpEx, $template, $cache;

    $limit = "12";
    $sql = "SELECT * FROM " . TOPICS_TABLE . " WHERE topic_approved = '1' ORDER BY topic_id DESC";
    $result = $db->sql_query_limit($sql, $limit, false);

    echo "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\" width=\"592\">
    <tr style='border: 1px solid #000;  background: #444;'>
    <td style='border: 1px solid #000;  background: url(images/bggg.png) repeat-x;'><center><img src=\"images/cs.png\" /></center></td><td style='border: 1px solid #000;  background: url(images/bg.png) repeat-x;'>Тема</td><td style='border: 1px solid #000;  background: url(images/bg.png) repeat-x;'>Автор</td><td style='border: 1px solid #000;  background: url(images/bg.png) repeat-x; text-align: center;'>Видяна</td><td style='border: 1px solid #000;  background: url(images/bg.png) repeat-x;'><center>Отговори</center></td>";

    while($topic = $db->sql_fetchrow($result)) {

    $topic_title = iconv("ISO-8859-1", "UTF-8", $topic['topic_title']));

    $sql2 = "SELECT * FROM " . USERS_TABLE . " WHERE user_id = '{$db->sql_escape($topic['topic_poster'])}'";
    $result2 = $db->sql_query_limit($sql2, 1, false);
    $topic_info = $db->sql_fetchrow($result2);

    echo "<tr><td style=\"border: 1px solid #000;  background: url(images/bg.png) repeat-x;\"><center><img src=\"images/cs.png\" /></center></td><td style='border: 1px solid #000;  background: url(images/bg.png) repeat-x;'><font color=\"white\"> <a href=\"{$phpbb_root_path}/viewtopic.php?f={$db->sql_escape($topic['forum_id'])}&t={$db->sql_escape($topic['topic_id'])}\" target=\"_blank\">{$db->sql_escape($topic_title)}</a></td><td style=\"border: 1px solid #000;  background: url(images/bg.png) repeat-x;\">{$db->sql_escape($topic_info['username'])}</td><td style='border: 1px solid #000;  background: url(images/bg.png) repeat-x;'>{$db->sql_escape($topic['topic_views'])}<td style='border: 1px solid #000; background: url(images/bg.png) repeat-x;'>{$db->sql_escape($topic['topic_replies'])}</td></tr>";

    }

    echo "</table>";

$db->sql_freeresult($result2);
$db->sql_freeresult($result);

?>

Re: request_var and normalize_nfc

Posted: Tue Feb 22, 2011 9:42 am
by 4_seven
u have a direct php/template mix in one file :shock:
try first to seperate them in phpbb3/template syntax, then it should work
http://www.phpbb.com/kb/article/add-a-n ... -to-phpbb/

Re: request_var and normalize_nfc

Posted: Tue Feb 22, 2011 10:41 am
by hah
..I'm telling you that I don't want to use template.

Here is a quote from the first post
As I said with template its find, but without..

Re: request_var and normalize_nfc

Posted: Tue Feb 22, 2011 11:41 am
by AmigoJack
hah wrote:

Code: Select all

<?php
...
    echo "...{$db->sql_escape($topic['forum_id'])}...{$db->sql_escape($topic['topic_id'])}...{$db->sql_escape($topic_title)}...";
...
?>
This doesn't make sense - sql_escape() is meant for concatenating data into an SQL command only. Furthermore we still see no encoding, since you haven't posted your HTML head (and where are your request_var() and normalize_nfc() calls?). I doubt iconv() is needed at all - lookup in which encoding your data is stored in the database table(s) (it should be UTF-8) and use this encoding consequently by saving your file in UTF-8 and specifying a HTML content encoding of UTF-8.