CakeFest 2025 Madrid: The Official CakePHP Conference

Voting

: max(five, nine)?
(Example: nine)

The Note You're Voting On

thomasNOSPAM at sportentranceNOSPAM dot com
22 years ago
To abbreviate links into '...' if they outreach a certain amount of space; use the preg_replace function instead.

For instance you grabbed the headlines of a news site for use on your own page and the lines are to long:

asuming the raw material is stored in $unedited;

$edited = preg_replace("/(>)([[:print:]]{52,})(<)/e", "'\\1'.substr_replace('\\2 ', '...', '48').'\\3'", $unedited);
echo $edited;

This will shorten strings longer than 52 characters into 51 characters, with the last being three dots...

<< Back to user notes page

To Top