- 论坛徽章:
- 1
|
- <?php
- $summary = url_to_link($summary);
- $summary = strip_tags_except($summary, array('a'), FALSE);
- ?>
- <?php
- function strip_tags_except($text, $allowed_tags, $strip=TRUE) {
- if (!is_array($allowed_tags))
- return $text;
- if (!count($allowed_tags))
- return $text;
- $open = $strip ? '' : '<';
- $close = $strip ? '' : '>';
- preg_match_all('!<\s*(/)?\s*([a-zA-Z]+)[^>]*>!',
- $text, $all_tags);
- array_shift($all_tags);
- $slashes = $all_tags[0];
- $all_tags = $all_tags[1];
- foreach ($all_tags as $i => $tag) {
- if (in_array($tag, $allowed_tags))
- continue;
- $text =
- preg_replace('!<(\s*' . $slashes[$i] . '\s*' .
- $tag . '[^>]*)>!', $open . '$1' . $close,
- $text);
- }
- return $text;
- }
- function url_to_link($text) {
- $text =
- preg_replace('!(^|([^\'"]\s*))' .
- '([hf][tps]{2,4}:\/\/[^\s<>"\'()]{4,})!mi',
- '$2<a href="$3">$3</a>', $text);
- $text =
- preg_replace('!<a href="([^"]+)[\.:,\]]">!',
- '<a href="$1">', $text);
- $text = preg_replace('!([\.:,\]])</a>!', '</a>$1',
- $text);
- return $text;
- }
- ?>
复制代码 |
|