src/Utility/StringHelper.php
public function wordWrap($text, $width = 72, $break = "\n", $cut = false) {

		if ($cut) {
			$parts = array();
			while (mb_strlen($text) > 0) {
				$part = mb_substr($text, 0, $width);
				$parts[] = trim($part);
				$text = trim(mb_substr($text, mb_strlen($part)));
			}

			return implode($break, $parts);
		}

		$parts = array();
		while (mb_strlen($text) > 0) {
			if ($width >= mb_strlen($text)) {
				$parts[] = trim($text);
				break;
			}

			$part = mb_substr($text, 0, $width);
			$nextChar = mb_substr($text, $width, 1);
			if ($nextChar !== ' ') {
				$breakAt = mb_strrpos($part, ' ');
				if ($breakAt === false) {
					$breakAt = mb_strpos($text, ' ', $width);
				}
				if ($breakAt === false) {
					$parts[] = trim($text);
					break;
				}
				$part = mb_substr($text, 0, $breakAt);
			}

			$part = trim($part);
			$parts[] = $part;
			$text = trim(mb_substr($text, mb_strlen($part)));
		}

		return implode($break, $parts);

	}
public function wordWrap($text, $width = 72, $break = "\n", $cut = false) {

		if ($cut) {
			$parts = array();
			while (mb_strlen($text) > 0) {
				$part = mb_substr($text, 0, $width);
				$parts[] = trim($part);
				$text = trim(mb_substr($text, mb_strlen($part)));
			}

			return implode($break, $parts);
		}

		$parts = array();
		while (mb_strlen($text) > 0) {
			if ($width >= mb_strlen($text)) {
				$parts[] = trim($text);
				break;
			}

			$part = mb_substr($text, 0, $width);
			$nextChar = mb_substr($text, $width, 1);
			if ($nextChar !== ' ') {
				$breakAt = mb_strrpos($part, ' ');
				if ($breakAt === false) {
					$breakAt = mb_strpos($text, ' ', $width);
				}
				if ($breakAt === false) {
					$parts[] = trim($text);
					break;
				}
				$part = mb_substr($text, 0, $breakAt);
			}

			$part = trim($part);
			$parts[] = $part;
			$text = trim(mb_substr($text, mb_strlen($part)));
		}

		return implode($break, $parts);

	}
public function wordWrap ( $ text , $ width = 72 , $ break = "\n" , $ cut = false ) { if ( $ cut ) { $ parts = array ( ) ; while ( mb_strlen ( $ text ) > 0 ) { $ part = mb_substr ( $ text , 0 , $ width ) ; $ parts [ ] = trim ( $ part ) ; $ text = trim ( mb_substr ( $ text , mb_strlen ( $ part ) ) ) ; } return implode ( $ break , $ parts ) ; } $ parts = array ( ) ; while ( mb_strlen ( $ text ) > 0 ) { if ( $ width >= mb_strlen ( $ text ) ) { $ parts [ ] = trim ( $ text ) ; break ; } $ part = mb_substr ( $ text , 0 , $ width ) ; $ nextChar = mb_substr ( $ text , $ width , 1 ) ; if ( $ nextChar !== ' ' ) { $ breakAt = mb_strrpos ( $ part , ' ' ) ; if ( $ breakAt === false ) { $ breakAt = mb_strpos ( $ text , ' ' , $ width ) ; } if ( $ breakAt === false ) { $ parts [ ] = trim ( $ text ) ; break ; } $ part = mb_substr ( $ text , 0 , $ breakAt ) ; } $ part = trim ( $ part ) ; $ parts [ ] = $ part ; $ text = trim ( mb_substr ( $ text , mb_strlen ( $ part ) ) ) ; } return implode ( $ break , $ parts ) ; }
Unicode aware version of wordwrap.

@param string $text The text to format.
@param integer $width The width to wrap to. Defaults to 72.
@param string $break The line is broken using the optional break parameter. Defaults to '\n'.
@param boolean $cut If the cut is set to true, the string is always wrapped at the specified width.
@return string Formatted text.
Unicode aware version of wordwrap .