PHP Cut String Tidak Memutus Kata

Berikut ini adalah daftar fungsi php bertujuan memotong string tapi tidak memotong kata

Contoh PHP Cut String 1

$new_word = substr($string, 0, strpos(wordwrap($string, $your_desired_width), "\n"));

Contoh PHP Cut String 1

$new_word = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $your_desired_width));

Contoh PHP Cut String 3

$new_word =  = substr($string, 0, strrpos(substr($string, 0, $your_desired_width), ' '));

Contoh PHP Cut String 4

Memotong dan menyimpan dalam bantuk array

$new_word_arr = explode( "\n", wordwrap( $string, $your_desired_width));

Demikian semoga bermanfaat
sumber : http://stackoverflow.com/questions/79960/how-to-truncate-a-string-in-php-to-the-word-closest-to-a-certain-number-of-chara
sumber: http://stackoverflow.com/questions/11254787/php-split-a-long-string-without-breaking-words

Leave a Reply

Your email address will not be published. Required fields are marked *



*