PHP or JS - Hide Name with more than X careteres

2

Using the phrase

"OLA SOU FIXE LALALA" 

How can I just show half, for example

"OLA SOU F..."
    
asked by anonymous 31.03.2018 / 17:58

1 answer

2

PHP:

 $string = "OLA SOU FIXE LALALA";
 $metade = strlen($string)/2;
 echo substr($string , 0, $metade).'...';

JS:

var string = 'OLA SOU FIXE LALALA';
var metade = string.length/2;
alert( string.substring(0, metade) + '...');
    
31.03.2018 / 18:08