Count of the number of words in the post (in case of a picture)

Source: Internet
Author: User
Count of the number of words in the post (in case of a picture)
Purpose
Post preview: When the number of words beyond a certain limit, the post is part of the display, the rest of the use. Display full text instead of

Background
Posts include Chinese, English, Rich text editor generated tags, pictures (also tags introduced), and post content is processed by Htmlspecialchars ()

"Current Difficulties"
1. I want the "part" of the post to show, this "part" hope is a volume that looks almost large, rather than the character on one side, because Utf-8, if it is a certain number of characters to limit, English posts and Chinese posts will have a significant volume of different results, I hope the final display, such as , it's all 5 rows.
2. Correct in the UTF-8 environment, do not put a Chinese character into two garbled characters
3. A post with a picture can be exactly the same, rather than dividing the label in the middle of the picture.
4. Thanks to the introduction of rich text editor, so a lot of content is tagged, this in the preview when it seems difficult to deal with, I think, simply preview the time without rich text those formats, but do not know if there is a way to remove these tags
5. I want to handle user input with Htmlspecialchars () because I want to consider the security of user input. However, those labels that were added to the text first, followed by Htmlspecialchars (), were also processed, and the results were displayed when the labels were displayed. So I first use Htmlspecialchars () to process user input, and then add rich text tags

"Implementation Examples"
I know that the preview of the Web is what I want to do when there is no problem.-no format, including graph, almost four or five lines

"The solution I think of now"
Storing the content as a formatted body and a truncated, unformatted preview makes the preview easier, but the question is how to get rid of the formatted text (before: the content is processed by the Rich Text editor before Htmlspecialchars (), and there is redundancy, I don't know if there's any good way.

Other
Rich text editor is generated by textarea, HTML-based, is basically tagged in

Last
I level too water, light describes this problem for a long time, you greatly hard, thanks to everyone who has read this post.
I think everyone should understand what I mean, right? I hope I don't get dizzy ...

Thank you in advance!!

In addition, my website: Mind Kee http://42.121.107.221 yesterday just on-line test, even the record has not been done, belongs to my personal hobby, is to write their own thoughts ah such a place, at the bottom of the page about we have this site positioning, are kindly invited you greatly come to the guidance!
------Solution--------------------
Picture size is different (such as a picture is just a small icon or logo), in order to avoid deformation, scaling is a standard bar, it is not possible to display the same size. If this factor is counted, the situation will be more complicated.

However, the more restrictive the conditions, the more concentrated and clear the method actually is. Get the size of the picture to participate in the display control. The problem of Chinese can also be solved.
------Solution--------------------
First look at the site of a number of bugs, there is time to use a summary of it.
------Solution--------------------
If you want a precise area of the word, the number alone is no good at all.
I have done this, the method is to create a div, the word (an IMG tag also as a word) to add one by one, if you find that the div height is higher than a preset value, the word deleted back. The efficiency is lower, but the result is good.
------Solution--------------------
#5 approach is called "enumeration method"
You can also use the dynamic programming method to treat each element (text, picture) as a rectangle and abstract the problem into a small rectangle filled with the largest rectangle. This is a classic algorithm, a lot of ready-made code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.