Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: comments UTF-8 characters problem �  (Read 1218 times)

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
comments UTF-8 characters problem �
« on: July 09, 2011, 10:09:20 PM »

For long time I have this problem in function new_comments
when someone write a comment in different language except English has output in the end the char �

to avoid that use mb_substr

find in function new_comments
Code: [Select]
$ncom = strlen($ncom) > $stringlen ? substr($ncom, 0, $stringlen - 3).'...' : $ncom;comment out and put
Code: [Select]
$ncom = strlen($ncom) > $stringlen ? mb_substr($ncom, 0, $stringlen - 3, 'UTF-8').'...' : $ncom;
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: comments UTF-8 characters problem �
« Reply #1 on: July 10, 2011, 12:33:32 AM »

I don't think this is an sNews bug - I've never come across this issue and I've had comments posted in a number of languages with non-English characters on my sNews sites as well as sites I've built for others with sNews. Never had a problem with it. There have been situations where people have seen the � character in articles but generally that happens when visitors are using browsers with reduced UTF-support (typically Chrome and iOS Safari). This doesn't mean the problem isn't real, and it's good for people to know about a solution, I just don't think it's a bug in sNews.
(I could be wrong of course.)
Logged

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: comments UTF-8 characters problem �
« Reply #2 on: July 10, 2011, 01:27:25 AM »

I write a comment in your site to test about the char (of course in Greek)  :)
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: comments UTF-8 characters problem �
« Reply #3 on: July 10, 2011, 05:25:24 AM »

Quote from: yor comment
σε ευχαριστώ πάρα πολύ για αυτή την εκπληκτική τροποποίηση μου έλυσε τα χέρια!

This is as it appeared. One thing I was thinking now is that on the site you commented on, I've done a modification of function file_include() in order for < and > tags not to be converted to HTML entities within the article text:
Code: [Select]
#   if(substr_count ($fulltext, '&')>0){$fulltext = str_replace('&', '&amp;', str_replace('&amp;', '&', $fulltext));}
I don't know if that change might also affect comments - I don't think it should, logically - but you never know... It was just a thought that came to me, but I'm sleep-deprived so it may be completely dim. ;)

// Edit
I've tried it a few times in a fresh sNews installation and had no problems with special chars...
« Last Edit: July 10, 2011, 05:27:27 AM by Fred K »
Logged

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: comments UTF-8 characters problem �
« Reply #4 on: July 10, 2011, 06:55:11 AM »

Can you try in fresh snews the comment I write,  I have <?php new_comments(5,50); ?>
and  for mysql have utf8_general_ci
I am very sure about this problem and this char doesn't  appear  all the times, depends off the last UTF-8 char and how is counting, some counts 3 chars some counts 2
(I don't have understand completely)

Try and make 3-4 comments in fresh snews with Greek comment and just and some spaces and you see the problem
like this
Quote
σε ευχαρι στώ πάρα πολύ για αυτή την εκπληκτική τροποποίηση μου έλυσε τα χέρια!
σε ευχαριστώ πάρα πολύ για αυτή την εκπλη κτική τροποποίηση μου έλυσε τα χέρια!
σε ευχαριστώ πάρα πολύ για αυτή την εκπληκτική τροπο ποίηση μου έλυσε τα χέρια!
σε ευχαριστώ πάρα πολύ για αυτή την εκπληκτική τροποποίηση μου έλυσ ε τα χέρια!

without mb_substr display this


with mb_subst display this







« Last Edit: July 10, 2011, 08:04:21 AM by sibas »
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: comments UTF-8 characters problem �
« Reply #5 on: July 10, 2011, 11:28:08 AM »

Hmm, yeah, okay I see the problem now. It does take some fiddling with the limit count to get it to show up when using a language with less special chars than Greek though, but, yes the problem is clear.
I'll add this to the update list for sNews 1.7. Thanks.
Logged

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: comments UTF-8 characters problem �
« Reply #6 on: July 10, 2011, 03:35:33 PM »

Thanks Sibas to report this.

Here is a solution for all, I hope.
Code: [Select]
if (mb_check_encoding($str,'UTF-8')) {
   $ncom = mb_strlen($ncom) > $stringlen ? mb_substr($ncom, 0, $stringlen - 3, 'UTF-8').'...' : $ncom;
} else {
   $ncom = strlen($ncom) > $stringlen ? substr($ncom, 0, $stringlen - 3).'...' : $ncom;
}
« Last Edit: July 10, 2011, 04:01:07 PM by Rui Mendes »
Logged
Need a Job on Europe. Linkdin - Facebook / Group

cixi

  • Newbie
  • *
  • Karma: 0
  • Posts: 6
Re: comments UTF-8 characters problem �
« Reply #7 on: May 10, 2012, 05:17:02 AM »

Chinese language is very usefull. :)

Many thanks
Logged