Hi there,
I have got a question,
say, I have some HTML content.
My problem is, how do I substring the content to generate a preview of x letters of the pure text with leaving the markup structure fully functioning?
I tried to strip the tags, then substr my wanted length, and then I tried a make up a regexp to do the same to the HTML thing, but of course wouldn't work.
Thanks for your help.
ur right, sorry, okay:
eg, I have got this:
<b>bla blub</b><i>this</i> <br>is the content I want to extract</i> bu
+t only some <span style="background:#ccc">part of it</span>
Now I want to provide a preview like that:
<b>bla blub</b><i>this <br>is the content I want to extract</i>but -
+> more?
if I just did substr($content,0,40) I would get something like:
<b>bla blub</b><i>this <br>is the content I want t
and you see that the HTML markup is broken, which I would like not to have.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.