PHP Shorten String Function

Today, We want to share with you PHP Shorten String Function.In this post we will show you php string functions, hear for php string length we will give you demo and example for implement.In this post, we will learn about php trim spaces before and after with an example.

PHP Shorten String Function

There are the Following The simple About PHP Shorten String Function Full Information With Example and source code.

As I will cover this Post with live Working example to develop php trim string, so the some php rtrim, ltrim in php for this example is following below.

function convertShotString($data, $length, $endCharData = '…') {
    if (is_string($data) === false) {
        return false;

    if (mb_strlen($data) > $length) {

        return mb_substr($data, 0, ($length - mb_strlen($endCharData))) . $endCharData;

    } else {

        return $data;



echo convertShotString('This is more text to pakainfo the website with.', 20); // This is more text t…
echo convertShotString('This is more text to pakainfo the website with.', 20, '...'); // This is more text t...
echo convertShotString('Pakainfo.', 20); // Pakainfo.
echo convertShotString('Pakainfo.', []); // Returns false

Angular 6 CRUD Operations Application Tutorials

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Shorten String Function.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1.   Download Remote File via PHP CURL
  2.   Shell Script to Add Two Numbers using ommand line arguments
  3.   Laravel PHP Artisan Commands list with Example
  4.   Model View Controller(MVC) in PHP Hello World Example
  5.   Get Drop Down List of TimeZones using PHP
  6.   Send Emails Using Laravel 6 Mailable Class?
  7.   sticky Scroll Back to Top Button using jQuery and CSS
  8.   Server-side processing Laravel DataTables
  9.   cPanel custom PHP.INI File Configuration
  10.   PHP String Explode and Implode Function