cut text after (x) amount of characters

后端 未结 5 1619
谎友^
谎友^ 2021-01-13 07:03

This is in wordpress (not sure that makes a difference)

This bit of php outputs the post title


         


        
5条回答
  •  误落风尘
    2021-01-13 07:39

    After you check the string length with strlen use substr

    $string = "This is a large text for demonstrations purposes";
    if(strlen($string) > 20) $string = substr($string, 0, 20).'...';
    echo $string;
    

    Outputs

    "This is a large text..."
    

提交回复
热议问题