How to pull first N 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.";
 
$N = 15;      
if (strlen($s) > $N)
    $s = substr($s, 0, $N) . "...";
 
echo $s;
 
 
/*
run:
  
PHP is a genera...
  
*/

 



answered Jul 29, 2020 by avibootz

Related questions

1 answer 160 views
1 answer 129 views
1 answer 149 views
1 answer 160 views
1 answer 108 views
1 answer 46 views
...