Get a number of characters from a string using PHP
I want to grab only the first 80 char开发者_StackOverflow社区acters from a string, $string
, using PHP.
Is there a function for that?
$result = substr($string, 0, 80);
I think you can use
substr($string, 0, 80);
Check it out: PHP equivilent of Javascript's substring()?
The text below was written by Nick Shepherd on the topic above.
$string = 'Foo Bar!';
$from = 2;
$to = 5;
$final_string = substr($string, $from, $to - $from);
or
$string = 'Foo Bar!';
$start = 2;
$length = 5;
$final_string = substr($string, $start, $length);
Try the substr function like,
$result = substr($string, 0, 80);
精彩评论