wordwrap() public static method

Minimal multi-byte wordwrap implementation which also takes break length into consideration
public static wordwrap ( string $str, integer $width, string $break = " " ) : string
$str string
$width integer
$break string
return string
Ejemplo n.º 1
0
 /**
  * The output text for the item
  *
  * @param MenuStyle $style
  * @param bool $selected
  * @return array
  */
 public function getRows(MenuStyle $style, $selected = false)
 {
     $marker = sprintf("%s ", $style->getMarker($selected));
     $length = $style->getDisplaysExtra() ? $style->getContentWidth() - (mb_strlen($style->getItemExtra()) + 2) : $style->getContentWidth();
     $rows = explode("\n", StringUtil::wordwrap(sprintf('%s%s', $marker, $this->text), $length, sprintf("\n%s", str_repeat(' ', mb_strlen($marker)))));
     return array_map(function ($row, $key) use($style, $marker, $length) {
         if ($key === 0) {
             return $this->showItemExtra ? sprintf('%s%s  %s', $row, str_repeat(' ', $length - mb_strlen($row)), $style->getItemExtra()) : $row;
         }
         return $row;
     }, $rows, array_keys($rows));
 }
Ejemplo n.º 2
0
 /**
  * The output text for the item
  *
  * @param MenuStyle $style
  * @param bool $selected
  * @return array
  */
 public function getRows(MenuStyle $style, $selected = false)
 {
     return explode("\n", StringUtil::wordwrap($this->text, $style->getContentWidth()));
 }