|
Posted by Stefan Rybacki on 07/20/05 00:23
Dave Moore wrote:
> Hi All,
> Here's my problem. I have a large textual entry in a database which I
> want to extract and display on a webpage using php. Everything's ok, so far.
> However, I only want to show the first 100 characters of the text, not all
> of it. The problem is that the text includes HTML tags. If I simply cut the
> text off at 100 characters, there's a chance that I will do so in the middle
> of a HTML tag which will then break the rest of the page.
>
> So my question is: can I use php to help me detect an appropriate place to
> cut the string?. Is there a neat function to do this or will I have to muck
> around with string analysis functions?. Alternatively is there a way to
> render the whole string but only make the first 100 characters visible?.
> Maybe this would be neater?.
>
> Any comments or suggestions gratefully received.
>
> Ta,
> Dave
>
>
>
>
you could use regular expressions to split the string into text and tags.
Regards
Stefan
[Back to original message]
|