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

Related questions

1 answer 176 views
1 answer 100 views
1 answer 105 views
1 answer 104 views
1 answer 156 views
...