Limit Displayed Characters From Your Text


Source : Limit Displayed Characters From Your Text

############### Code

$position=14; // Define how many characters you want to display.

$message="You are now joining over 2000 current";
$post = substr($message,$position,1); // Find what is the last character displaying. We find it by getting only last one character from your display message.

if($post !=" "){ // In this step, if last character is not " "(space) do this step .

// Find until we found that last character is " "(space)
// by $position+1 (14+1=15, 15+1=16 until we found " "(space) that mean character 20)
while($post !=" "){
$i=1;
$position=$position+$i;

$message="You are now joining over 2000 current";
$post = substr($message,$position,1);
}

}

$post = substr($message,0,$position); // Display your message
echo $post;
echo "…";

Related Posts: