tags:

views:

60

answers:

2

It introduced a lot of non-closed tags like below:

<div>
<table>...</table>

The </div> is truncated by code like this:

(strlen($row['body']) > 200 ? substr($row['body'],0,200) . '...' : $row['body'])

And the layout of the whole page is broken,how to deal with it?

+1  A: 

Assuming that $row['body'] contains HTML that you want to truncate to 200 visible characters:

Strip out HTML Tags

This is the quickest fix but may not be what you want:

$body= strip_tags($row['body']);
echo(strlen($body) > 200 ? substr($body,0,200) . '...' : $body);

Parse HTML and truncate text

Using PHP's DOMDocument class you can parse the HTML, check the length of text within HTML tags, count the length of text in the content, and remove any tags after the character limit from the HTML contained in $row['body'] while retaining well-formed HTML.

pygorex1
A: 

I assume you have left it out for brevity but I see no tags

it should be

<div>
<table><tr><td>...</td></tr></table>

Also use the following you may have html embedded in your $row['body']

(strlen($row['body']) > 200 ? substr($row['body'],0,200) . '...' : htmlspecialchars($row['body']))

DC

DeveloperChris