Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I seem to recall the CB had this problem a few years ago, and it was solved... and now I'm running into it.

Here's the situation:

I have a database of news articles, which I query for 3 random entries. I clip the article summary at 200 characters and display the result. I'm using MySQL to clip the articles, like so:

$news_sth = $dbh->prepare (qq{ SELECT article_id, article_title, LEFT(article_body, 220) AS CLIP, DATE_FORMAT(article_date, '%W %M %D %Y') as my_date from news_articles group by article_id order by RAND() LIMIT 3});

This part works great... until 200 characters happens to fall right in the middle of an open HTML tag.

This is some random HTML from one of my <em>news articles that would be clipped...

Note in the above example, I've clipped after the opening <em> tag, but not after the matched closing tag.

What I'm trying to figure out, is...

  1. Should I be clipping with MySQL? Or substr() in Perl?
  2. Is there a way to "rewind" to the last open tag, so I can close it at the end of my clipped section?
  3. Another method?

The problem is most obvious when I'm clipping in the middle of a blockquote section or an ordered/unordered list. When the next article is drawn, it inherits the formatting left over from the previous open tag.

Yuck.

How should I best approach a fix for this?


In reply to Clipping text in the middle of an open HTML tag by hacker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (None)
    As of 2024-04-25 01:03 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found