Greetings. Once I have found such a useful site, I will torment everyone here :).

On my site there is a conclusion of articles. And in the database, you have to create two special lines in the table - "Text" and "Description" (which goes to the button << Details >>). How to do that from the "Text" to display a certain number of characters or words (and not use a few extra lines in the database). I hope clearly explained :).

Thank you in advance.

  • @GLAGOLA ^ _ ^ I have already solved the problem) but thanks for answering with an example and in detail :) - Root

2 answers 2

It is logical to assume that before the "Details" button there should be a whole paragraph (or several), and let's say not half of the sentence, so you need to decide what number of paragraphs you want to see before the book. "Read more."

Next, run the script (where $text is the text of the article, $title is the name of the article, $paragraph_count is the number of paragraphs before "Details", suppose paragraphs in the database are stored framed with the <p>...</p> ):

 $title = 'Some article'; $text = <<<TEXT <p>These escaped characters are not very useful for outputting to a web page because HTML ignore extra white space.</p> <p> A tab, newline, and carriage return are all examples of extra (ignorable) white space.</p> <p>However, when writing to a file that may be read by human eyes these escaped characters are a valuable tool!</p> TEXT; $paragraph_count = 3; if (preg_match_all('/\<p\>.*?\<\/p\>/', $text, $matches)) { echo 'Название статьи - '.$title.'<br />'; echo implode('', array_slice($matches[0], 0, $paragraph_count)); echo ' Подробнее >>>'; } 

    Somehow the question is not correct, and do not understand what exactly you need. If correctly understood:

      echo mb_substr($sql['txt'],0,20,"UTF-8").'..' echo '<a href="#">Подробнее...</a>';