开发者

Get a number of characters from a string using PHP

开发者 https://www.devze.com 2023-02-01 17:37 出处:网络
I want to grab only the first 80 char开发者_StackOverflow社区acters from a string, $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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号