Example #1
0
 static function trim($value, $max_length, $is_html = false)
 {
     if (UTF8::len($value) > $max_length) {
         $value = UTF8::sub($value, 0, $max_length);
         // TODO: replace this with cleanstring of ctools
         $regex = '(.*)\\b.+';
         $matches = array();
         if (function_exists('mb_ereg')) {
             mb_regex_encoding('UTF-8');
             $found = mb_ereg($regex, $value, $matches);
         } else {
             $found = preg_match("/{$regex}/us", $value, $matches);
         }
         if ($found) {
             $value = $matches[1];
         }
         if ($is_html) {
             // Remove scraps of HTML entities from the end of a strings
             $regex = '/(?:<(?!.+>)|&(?!.+;)).*$/s';
             $value2 = preg_replace($regex . 'u', '', $value);
             if (preg_last_error() == 4) {
                 $value = preg_replace($regex, '', $value);
             } else {
                 $value = $value2;
             }
         }
         $value = rtrim($value);
         $value .= '...';
     }
     if ($is_html) {
         $value = self::_filter_htmlcorrector($value);
     }
     return $value;
 }
Example #2
0
 /**
  * @param $url
  * @return URL
  */
 static function fromURLorPath($url)
 {
     $ret = parse_url($url);
     if (isset($ret['scheme'])) {
         $ret['scheme'] = UTF8::lower($ret['scheme']);
         $ret['host'] = UTF8::lower($ret['host']);
     }
     return new static($ret);
 }