本文整理匯總了PHP中string::trim_text方法的典型用法代碼示例。如果您正苦於以下問題:PHP string::trim_text方法的具體用法?PHP string::trim_text怎麽用?PHP string::trim_text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類string
的用法示例。
在下文中一共展示了string::trim_text方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: return_relevant
/**
* Try to find searched value and return whole sentence
* @return string sentence without html
* @param string to search in
* @param string to be searched
*/
public function return_relevant($value, $search)
{
if (empty($search)) {
return;
} else {
$value = strip_tags($value);
$word_pos = strpos($value, $search);
// Find position of searched word
if ($word_pos === FALSE) {
// If there is no position, return first sentence
$next_fullstop = strpos($value, '. ', 0);
if ($next_fullstop === FALSE) {
// If there is no fullstop then truncate to certain length
return string::trim_text($value, 100) . '...';
} else {
return substr($value, 0, $next_fullstop) . '...';
}
} else {
$next_fullstop = strpos($value, '. ', $word_pos);
if ($next_fullstop === FALSE) {
// If there is no fullstop then truncate to certain lenght
return string::trim_text($value, 100) . '...';
} else {
$prev_fullstop = self::rstrpos($value, '. ', $word_pos);
return '...' . substr($value, $prev_fullstop, $next_fullstop - $prev_fullstop) . '...';
}
}
}
}