How to split a string in two parts without cutting words PHP? -


i have code cuts string $txt0 in 2 parts when lenght greater 64 characters. problem cuts word giving me result like:

$txt0 = "this house ... , pretty"   ----result----  house is...and rel  ly pretty   $array_posiciones = array (-250, -200, -150, -100, -50);  $posicion_lineas = 0; if ( !empty($txt0) )   {       if ( strlen($txt0) > 64 )        {           $lines = str_split($txt0, 40);           $listing_title->annotateimage($draw, 0, $array_posiciones[$posicion_lineas], 0, $lines[0]."-");           $posicion_lineas++;           $listing_title->annotateimage($draw, 0, $array_posiciones[$posicion_lineas], 0, $lines[1]);           $posicion_lineas++;       } else {           $listing_title->annotateimage($draw, 0, $array_posiciones[$posicion_lineas], 0, $txt0);           $posicion_lineas++;       }   } 

i trying draw 2 clean lines on image using imagick moment can avoid cut word when separated lines. thank , sry poor english. hope can understand question.

$txt0_short0=substr($txt0,0,strrpos($txt0," ",64)); $txt0_short1=substr($txt0,strrpos($txt0," ",64)); 

it starts first position of " " after frst 64 char , uses point split.


Comments