Welcome to UPOsoft!Welcome to UPOsoft!
Displaying part of a string
In this tutorial I am going to show you how you can display only part of a string and follow it by 3 dots (...). It's easier than you may think, you have to use the substr function. You need to start by setting a string and count the number of characters in that string.

$string = "This is the string that I want to shorten";
$string_length = strlen($string);

The value of $string_length will now be 40 as an integer, but knowing the data type is not important for this tutorial.

Next we will output part of the string, say we want to display 25 characters followed by ...

if($string_length > 25){
    echo(substr($string, 0, 25));
    echo("...");
}else{
    echo($string);
}

And that's it... It really is that easy, why not try it for yourself

 
The Result...
This is the string that I...
 
Members
Username:
Password: