Hi, I use the code below so as to print a text:

$query_a = "SELECT * FROM table WHERE id=(SELECT MAX(id) FROM table)";
$result_a= mysql_query($query_a) or die(mysql_error());  
$text_a = stripslashes(nl2br($row_a["text"]));

echo "<div class='uneven post'>";
echo "<p align='justify'>".$text_a."</p>";
echo "</div>";

In variable $text is stored text from a textarea (form).

The code is Ok , the problem I have is that the whole text is printed, while I would prefer to print the two first lines from text or the text until the first fullstop ('.').

I ask it because then I want to use a link , for instance more which direct in another page.

Could someone help me ??

Thanks a lot!

Hey.

If you only want to print the first sentence (up until the first period), you can do something like:

<?php
function getFirstSentence($text, $delimiter=".")
{
    return substr($text, 0, stripos($text, $delimiter) + 1);
}
?>

Also, you can get rid of the sub-query from your SQL query by doing:

SELECT * FROM table ORDER BY id DESC LIMIT 1

Should improve performance. (In theory, at least ;-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.