Skip to the content
Documentation

Beware of entities

No ratings yet

The final string length take in count the length of the substitution string.
$str|shorten(count($alt),$alt) permet donc de remplacer la chaîne $str par $alt dès que $str est plus longue que $alt.
Let test the ellipsis :
|shorten(80)
Lorem ipsu10m dolor 20sit amet30, consec40tetur ad50ipisicin60g elit, 70sed...
|shorten(80,'')
Lorem ipsu10m dolor 20sit amet30, consec40tetur ad50ipisicin60g elit, 70sed do
|shorten(80,'…')
Lorem ipsu10m dolor 20sit amet30, consec40tetur ad50ipisicin60g elit, 70sed d…
|shorten(80,'…')
Lorem ipsu10m dolor 20sit amet30, consec40tetur ad50ipisicin60g elit,…
|shorten(87,'…')
Lorem ipsu10m dolor 20sit amet30, consec40tetur ad50ipisicin60g elit, 70sed d…
If you don't want the ellipsis, just say it.
If you wan't the UTF-8 real ellipsis, use the HTML entity and add 7 to the desired length to correct the entity count.

Comments (1 historical)

Written by readers of the earlier documentation sites, kept as they were.

  1. Re: Beware of entities

    Adrien ·

    Notice that using directly the UTF-8 char simply doesn't work in my case. Can someone check if shorten deals with UTF-8 chars correctly? And I'm sudendly affraid by what's gonna happen next time I'll have to pass a UTF-8 char to a string function…