2015-05-08 41 views
1

我有这样的代码,当长度大于64个字符时,会将字符串$ txt0分为两部分。问题是,有时削减一句话给我一个结果,如:如何将字符串拆分为两部分而不使用单词PHP?

$txt0 = "This house is ... and really pretty" 


----result---- 

This 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++; 
     } 
    } 

我试图绘制图像上的简洁线条使用imagick但目前我能避免切一个字时,我隔线。谢谢你,我的英语不好。我希望你能理解这个问题。

+0

阅读[strpos](http://php.net/strpos)和[strstr](http://php.net/manual/en/function.strstr.php)。 –

回答

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

它从" "的FRST 64焦炭后的第一个位置开始,并使用该作为点拆分。

相关问题