Missing Closing Tags In Database Description (mysql)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bidntrade
Forum Commoner
Posts: 33
Joined: Thu Jul 02, 2009 9:54 pm

Missing Closing Tags In Database Description (mysql)

Post by bidntrade »

I imported products using a csv file to my database ...

I use php and mysql ....
there is about 4000 products in the database ....

during import for some reason there are a few here and there
that are missing some of there closing html tags from there descriptions .
this causes the page to look funny when viewing those items ....

looks like the ones messed up are missing

Code: Select all

</li>
</ul>
</div>
</div>
my database table is :
cscart_product_descriptions

and the field that has the html descriptions is :
full_description

are there a way i can search the database for ones that are missing closing html tags and fix them ? does anyone have a script to do this ?

problem is not all the descriptions are supposed to have these ...
it would be best if there was a way to go through each description field
one at a time and check the description with a function for missing closing tags
and then add them if needed .

then update database....


any help ?
bidntrade
Forum Commoner
Posts: 33
Joined: Thu Jul 02, 2009 9:54 pm

Re: Missing Closing Tags In Database Description (mysql)

Post by bidntrade »

ok i found this little piece of code taken from :
http://snipplr.com/view.php?codeview&id=3618

any idea how i would create a loop to open each of my database descriptions
send it through the function and update the decription in the database
if it was changed ?

Code: Select all

function closetags ( $html )
{
    #put all opened tags into an array
    preg_match_all ( "#<([a-z]+)( .*)?(?!/)>#iU", $html, $result );
    $openedtags = $result[1];
 
    #put all closed tags into an array
    preg_match_all ( "#</([a-z]+)>#iU", $html, $result );
    $closedtags = $result[1];
    $len_opened = count ( $openedtags );
    # all tags are closed
    if( count ( $closedtags ) == $len_opened )
    {
        return $html;
    }
    $openedtags = array_reverse ( $openedtags );
    # close tags
    for( $i = 0; $i < $len_opened; $i++ )
    {
        if ( !in_array ( $openedtags[$i], $closedtags ) )
        {
            $html .= "</" . $openedtags[$i] . ">";
        }
        else
        {
            unset ( $closedtags[array_search ( $openedtags[$i], $closedtags)] );
        }
    }
    return $html;
}
Post Reply