How to pull first 20 characters of a string in PHP

1 Answer

0 votes
$s = "PHP is a general-purpose scripting language 
      that is especially suited to web development.";

if (strlen($s) > 20)
    $s = substr($s, 0, 20) . "...";

echo $s;


/*
run:
 
PHP is a general-pur...
 
*/

 



answered Jul 29, 2020 by avibootz
edited Jul 29, 2020 by avibootz
...