📜  字符串长度 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:23.908000             🧑  作者: Mango

代码示例1
// strip tags to avoid breaking any html
$string = strip_tags($string);
if (strlen($string) > 500) {

    // truncate string
    $stringCut = substr($string, 0, 500);
    $endPoint = strrpos($stringCut, ' ');

    //if the string doesn't contain any space then it will cut without word basis.
    $string = $endPoint? substr($stringCut, 0, $endPoint) : substr($stringCut, 0);
    $string .= '... Read More';
}
echo $string;