Formatting txt from a database
| From: | Lisi | Date: | Thu, 12 Dec 2002 08:55:00 +0000 |
| Subject: | Formatting txt from a database | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-24082@lists.php.net to get a copy of this message | ||
I am retrieving text stored in a database, and I want to strip out any HTML tags and then only display the first 30 characters with "..." to show the user that there is more text to view.
My problem is with stripping out HTML tags, the code is stripping out the text enclosed within the HTML tags as well.
Here is the code I am using:
$pat = "<{1}.+>{1}";
if (ereg("text", $type)){ //if the field type is text look for HTML tags to remove
$content_array[$c] = ereg_replace($pat, '', $content_array[$c]);
$content_array[$c] = substr($content_array[$c], 1, 30);
$content_array[$c] = $content_array[$c]."...";
}
echo $content_array[$c];
What should the correct $pat be?
Thanks,
-Lisi