]*)>(.*?)<\/a>/uis', $string, $matches1); preg_match_all("/]*>(.*?)<\/a>/uis", $string, $matches2); if (!empty($matches1[1])) { foreach ($matches1[1] as $k => $v) { $matches[] = array('title' => trim($matches1[2][$k]), 'attribs' => trim($v)); } } if (!empty($matches2[1])) { foreach ($matches2[1] as $k => $v) { $matches[] = array('title' => trim($matches2[2][$k]), 'attribs' => trim($v)); } } unset($matches1, $matches2); $string = strip_tags($string); $string = trim($string); //$string = smarty_modifier_truncate($string, $length, $etc, $break_words, $middle); if (!empty($matches)) { foreach ($matches as $link) { if (strpos($string, $link['title']) !== false) { $string = preg_replace( '/' . preg_quote($link['title'], '/') . '(?!<\/a>)/u', "{$link['title']}", $string ); } else { do { $link['title'] = substr($link['title'], 0, strrpos($link['title'], ' ')); $link['title'] = trim($link['title']); if (strpos($string, $link['title'] . $etc) !== false) { $string = preg_replace( '/' . preg_quote($link['title'], '/') . '(?!<\/a>)/u', "{$link['title']}", $string ); break 2; } } while (strpos($link['title'], ' ') !== false || strlen($link['title'])); } } } return $string; }