t('Link Icons filter')); case 'description': return t('Bla bla'); case "process": return preg_replace_callback('!<(a[^>]+)>!i', 'linkicons_callback', $text); default: return $text; } } function linkicons_callback($matches) { if (preg_match('/href=([\'"][^\'"]+[\'"]|[^ ]+)[ >]/i', $matches[0], $href) && strstr($href[1], '.')) { list($extension) = array_reverse(explode('.', $href[1])); $extension = strtolower(preg_replace('![^A-Za-z0-9]!', '', $extension)); if ($extension != '') { if (preg_match('/class=/i', $matches[0])) { return preg_replace('!class=["\']?!', '\0url-'. $extension .' ', $matches[0]); } else { return '<'. $matches[1] . ' class="url-'. $extension .'">'; } } } return $matches[0]; } $text = <<test test test.xml test.foo.xml test.ppt class fooo bar DOC; print nl2br(linkicons_filter('process', 0, -1, $text)); ?>