Php text shortening function

You can use this simple code to shorten the article with php.
<?php 
$shortenedtext="You can use this simple code to shorten the article with php..";
public static function shorten($word, $str = 10)	{
		if (strlen($word) > $str)	{
			if (function_exists("mb_substr")) $word = mb_substr($word, 0, $str, "UTF-8").'..';
			else $word = substr($word, 0, $str).'..';
		}return $word;
		}
?>

<!--In the echo example below, we enter the text to be shortened by two values ​​and the number of characters. Our function makes the abbreviation according to these values ​​and adds 3 points.-->
<p><?= $fonks->shorten($shortenedtext,80);?></p>
Revise the code according to the variable you have defined in your functions file. Check if the PHP version you are using has mb string extension. It may cause this function not to work in some php configurations and versions.
E.Albayrak

0 Yorum

Soru & Yorum


Web Tasarım

Renkli Kare

Web Tasarım Ajansı