Bolt\Helpers\Str::shyphenate PHP Method

shyphenate() public static method

Add 'soft hyphens' ­ to a string, so that it won't break layout in HTML when using strings without spaces or dashes. Only breaks in long (> 19 chars) words.
public static shyphenate ( string $str ) : string
$str string
return string
    public static function shyphenate($str)
    {
        $res = preg_match_all('/([a-z0-9]{19,})/i', $str, $matches);
        if ($res) {
            foreach ($matches[1] as $key => $match) {
                $str = str_replace($match, wordwrap($match, 10, '­', true), $str);
            }
        }
        return $str;
    }

Usage Example

Example #1
0
 /**
  * Add 'soft hyphens' ­ to a string, so that it won't break layout in HTML when
  * using strings without spaces or dashes.
  *
  * @param string $str
  *
  * @return string
  */
 public function shy($str)
 {
     if (is_string($str)) {
         $str = Str::shyphenate($str);
     }
     return $str;
 }