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 ' Подробнее >>>'; }