PHPverse 2025

Voting

: min(one, six)?
(Example: nine)

The Note You're Voting On

rob NOSPAM at clancentric dot net
19 years ago
I have developed a function with a similar outcome to jay's

Checks if the last character is or isnt a space. (does it the normal way if it is)
It explodes the string into an array of seperate works, the effect is... it chops off anything after and including the last space.

<?php
function limit_string($string, $charlimit)
{
if(
substr($string,$charlimit-1,1) != ' ')
{
$string = substr($string,'0',$charlimit);
$array = explode(' ',$string);
array_pop($array);
$new_string = implode(' ',$array);

return
$new_string.'...';
}
else
{
return
substr($string,'0',$charlimit-1).'...';
}
}
?>

<< Back to user notes page

To Top