/** * nv_substr_clean() * * @param mixed $string * @param string $mode * @return */ function nv_substr_clean($string, $mode = 'lr') { $strlen = nv_strlen($string); $pos_bg = nv_strpos($string, " ") + 1; $pos_en = nv_strrpos($string, " "); if ($mode == 'l') { $string = "..." . nv_substr($string, $pos_bg, $strlen - $pos_bg); } elseif ($mode == 'r') { $string = nv_substr($string, 0, $strlen - $pos_en) . "..."; } elseif ($mode == 'lr') { $string = "..." . nv_substr($string, $pos_bg, $pos_en - $pos_bg) . "..."; } return $string; }
/** * nv_strrpos() * * @param mixed $haystack * @param mixed $needle * @param mixed $offset * @return */ function nv_strrpos($haystack, $needle, $offset = null) { if (is_null($offset)) { $ar = explode($needle, $haystack); if (count($ar) > 1) { array_pop($ar); $haystack = join($needle, $ar); return nv_strlen($haystack); } return false; } else { if (!is_int($offset)) { trigger_error('nv_strrpos expects parameter 3 to be long', E_USER_WARNING); return false; } $haystack = nv_substr($haystack, $offset); if (false !== ($pos = nv_strrpos($haystack, $needle))) { return $pos + $offset; } return false; } }