php - List Title But End At Last Word -


i have site listing titles, , since each title larger our needed space have use following code break down if larger amount of characters, , show ...:

<?php $title = get_the_title(); echo mb_strimwidth($title, 0, 45, '...'); ?> 

is there way possibly list amount of words, instead of characters, can @ least have full word @ end of title instead of character , ...?

any appreciated. on wp system.

since you're using multi-byte string functions, can do:

if (mb_strlen($title) > 45) {     $title = mb_substr($title, 0, 45);     // make sure ends in word chomping @ last space     $title = mb_substr($title, 0, mb_strrpos($title, " ")).'...'; }  echo $title; 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -