Exemple #1
0
 /**
  * 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) . '...';
             }
         }
     }
 }