PHP or JS - Hide Name with more than X careteres

Asked

Viewed 28 times

2

Using the phrase

"OLA SOU FIXE LALALA" 

how can I only show half, for example

"OLA SOU F..."
  • 2

    Here’s a more sophisticated way to do it: https://answall.com/q/155204/101

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) + '...');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.