Using PHP, we can shorten the length of our string and just replace the rest with three dots.
This is usually needed in a software application, especially when the string length is too long to show to the user.
So we will write a function that is re-usable and which we can always call or use in any other programming.
function trimString($string, $repl, $limit)
{
if(strlen($string) > $limit)
{
return substr($string, 12, $limit) . $repl;
}
else
{
return $string;
}
}
?>
echo trimString("Hello Codeflare", "...", 3);
The trimString function we created takes three (3) parameters:
Next, we check if the length of the given string is greater than the limit which we have set. If it is, we truncate it and append our three dots. If it’s not, we just return the given string.
This is how we shorten the length of a string and replace it with three (3) dots in PHP.
Let me know what you think in the comments.
The South Korean government announced on Monday that it had temporarily halted new downloads of…
As a software developer, choosing the right programming language for software development can be a…
A server farm, also known as a server cluster or data center, is a collection…
Pakistan's mobile and broadband internet speeds rank in the bottom 10 percent globally, according to…
React Native is a popular framework for building cross-platform mobile applications using JavaScript and React.…
Google is not only passionate about developing innovative apps and services but also about finding…