Skip Navigation

[Résolu] Limited number of characters for Cyrillic

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How to Limit number of characters for Cyrillic special characters

Solution:
The character encoding issues are specific to your current install.

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/limited-number-of-characters-for-cyrillic/#post-605890

Relevant Documentation:

This support ticket is created Il y a 6 années et 3 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Marqué : ,

This topic contains 6 réponses, has 2 voix.

Last updated by anastasiaP Il y a 6 années et 3 mois.

Assisted by: Minesh.

Auteur
Publications
#604906

Hello!

I need display limited number of characters on website.

I use this code (create shortcode):

add_shortcode('limit_content', 'trim_shortcode');
 function trim_shortcode($atts, $content = '') {
    $content = wpv_do_shortcode($content);
    $length = (int)$atts['length'];
  
    if (strlen($content) > $length) {
        $content = substr($content, 0, $length) . '…';
    }
  
    // Strip HTML Tags
    $content = strip_tags($content);
  
    return $content;
}

And after use this shortcode in "Views":

[limit_content length="300"][types field='cpf-name' output='word'][/types][/limit_content]

It works perfectly, but not correct for "Cyrillic" (Russian).

U can see it on this screenshot - hidden link

#604941

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

WEll - It looks like character encoding issue.

Could you please try to use following shortcode (remove the code used before) where I've encode the string to utf8.

add_shortcode('limit_content', 'trim_shortcode');
 function trim_shortcode($atts, $content = '') {
    $content = wpv_do_shortcode($content);
    $length = (int)$atts['length'];
   
    if (strlen($content) > $length) {
        $content = substr($content, 0, $length) . '…';
    }
   
    // Strip HTML Tags
    $content = strip_tags($content);
   
    return utf8_encode($content);
}
#605018

Hi Minesh!

Thnx for answer, but after changing I see big problems with encode.
U can see it on screen - hidden link

#605019

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can I have problem URL and access details so I can check whats going wrong there.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#605626

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thanks for sharing access details.

I think you missed to share problem URL. Could you please send me problem URL where you've added above shortcode.

#605890

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added another shortcode to limit words as the issue is when word is break due to number of character.

add_shortcode('limit_words', 'trim_words_shortcode');
 function trim_words_shortcode($atts, $content = '') {
    $content = trim(wpv_do_shortcode($content));
	
    $length = (int)$atts['words'];
    	
	$content =	implode(' ', array_slice(explode(' ', $content), 0,$length));
    
	// Strip HTML Tags
    $content = strip_tags($content);
  
    return $content."...";
}

And you need to use as given under:

[limit_words words="25"][types field='eva-text-kommentariya' output='word'][/types][/limit_words]

I suggest you to apply above shortcode where ever you required.

#605902

Awesome!
Thank U very much!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.