use utf8_substr function instead of substr

17 years 1 week ago #37371 by baijianpeng
use utf8_substr function instead of substr was created by baijianpeng
Maybe most Joomla extension developers can't imagin that if they use function substr to get first x characters of a string will cause problem to Chinese users especially when utf-8 encoding was used on the website.

I installed the CB Profile Gallery plugin version 1.0RC2+ today on www.uhiker.com . You can see it works well on upper part of the left column EXCEPT that the shortened image title in the footer is showing unreadable symbols in the end.

See attached screen shot. The string of the alt text is the correct title, but the footer string is not.

There is a file called utf8.php that can solve this problem. A function named utf8_substr was defined in this file and was dedicated to replace function substr. Chinese translators had already packed this file in the Joomla Chinese version in <root>/includes directory.

I had attached the utf8.php file to let you know what is it.

I hope the author of CB Profile Gallery as well as other developers will consider to use function utf8_substr when whey want to get a shortened title or description from the longer original one.

Thanks.

Attachment utf8.zip not found


JoomlaGate

www.joomlagate.com
Attachments:

Please Log in to join the conversation.

17 years 6 days ago #37407 by nant
Thanks alot for your feedback!

Will certainly add this to next version!

Please Log in to join the conversation.

17 years 6 days ago #37410 by beat
Thanks for pointing us to this problem.

Is that spot the only problem that you have with utf-8 and Community Builder or are there others ?

Thanks also for submitting the solution, which works for Joomla 1.0. A similar library is also implemented in Joomla! 1.5, and problem is its namespace conflicts with this library, making it incompatible as is.

I've not yet decided on the final solution to this problem, but it will also depend on the extent of this problem, thus my first question :)

Thanks in advance for your replies,

Beat - Community Builder Team Member

Before posting on forums: Read FAQ thoroughly -- Help us spend more time coding by helping others in this forum, many thanks :)
CB links: Our membership - CBSubs - Templates - Hosting - Forge - Send me a Private Message (PM) only for private/confidential info

Please Log in to join the conversation.

17 years 6 days ago #37422 by baijianpeng
Replied by baijianpeng on topic Re:use utf8_substr function instead of substr
I have not done more tests. But I am sure many extensions have similar problem with Chinese characters when they want to cut part of a string using function substr.

It seemed that Joomla 1.0.x developers never considered to add utf8.php into the core. So those extension developers can't find a solution.

But the translators in China had already realized this issue and added utf8.php to /includes folder.

I know few about Joomla 1.5. I only care about the result. If you can make it work properly, it is OK and I don't care what kind of solution you will take.

In fact, the most simple solution is let user difine the length of the image title showed as footer (or header) ,if the specified length is longer than the real length of the title, then there will be no problem since substr function will cut the whole title.

Thank you all.

JoomlaGate

www.joomlagate.com

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.200 seconds

Facebook Twitter LinkedIn