简体   繁体   中英

How to remove html formatting effect in CSS styles

I am working on a simple php-MySql website and presenting the data for the following fields for each entry in the database (through a loop):

  1. Title

  2. Organisation

  3. DetailedInfo

The 'DetailedInfo' field in the database can hold up to 5000 characters. While displaying on the webpage I am only using the first 250 characters.

The problem is as follows. If an entry has a formatting tag (italic/bold) starting, say at character 240, and the formatting tag is not closed by the 250th character then the problem starts. For all subsequent entries the Title, Organisation and DetailedInfo are displayed with the tag (so all the subsequent text are either italic, or, bold). I am using CSS style for Title, Organisation and DetailedInfo but it seems that the CSS is not able to get rid of the formatting tag from the data.

Any help will be appreciated. Cheers, Tim

If you're only displaying a small portion of the detailedInfo field I'd guess formatting it isn't that mportant. Use strip_tags() to get rid of the formatting tags before you display it.

CSS cannot fix broken HTML. You'll need to strip it back to plain text and re-code (or just leave it out).

I wouldn't fix that with CSS (and I don't think it's possible). You're outputting invalid HTML, which is going to cause problems, especially if anyone ever looks a the page in IE 8 or earlier.

It could also be worse than an unclosed tag. What if the excerpt ends with </i ?

I'd either implement some crazy logic to close any unclosed HTML tags in the 250-character excerpt, or strip all HTML tags from the excerpt. I'm guessing the latter would be easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM