Posted By

chupzzz on 06/22/12


php String cut unicode utf-8

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Cut long string to n symbols preserving words (UTF-8)

 / Published in: PHP

Cut the string to needed length with keeping words.

  1. <?php
  2. $max_length = 150;
  3. $string = preg_replace('/\s+?(\S+)?$/', '', mb_substr($long_string, 0, $max_length));
  4. ?>

Report this snippet  

You need to login to post a comment.