Limit String Length

后端 未结 10 1234
不思量自难忘°
不思量自难忘° 2020-12-01 03:56

I\'m looking for a way to limit a string in php and add on ... at the end if the string was too long.

10条回答
  •  既然无缘
    2020-12-01 04:53

    In another way to limit a string in php and add on readmore text or like '...' using below code

    if (strlen(preg_replace('#^https?://#', '', $string)) > 30) { 
        echo substr(preg_replace('#^https?://#', '', $string), 0, 35).'…'; 
    }
    

提交回复
热议问题