0

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!

Edited by bufospro: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Atli
0

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 ;-)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.