Re: Formatting txt from a database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



$select="select fields from table...";
$sres=mysql_query($select);
echo mysql_error();
while ($srow=mysql_fetch_row($sres))
{
    $string=$srow[0];
    $no_html=strip_tags($string);
    if (strlen($no_html) > 30) $no_html=substr($no_html,0,30)."...";
    echo("$no_html");
}

Matt
----- Original Message -----
From: Lisi <lists@shemeshdirectory.co.il>
To: PHP-DB <php-db@lists.php.net>
Sent: Thursday, December 12, 2002 3:55 AM
Subject:  Formatting txt from a database


> 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
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux