Forum Moderators: coopster

Message Too Old, No Replies

Snipping length of text output

Cannot figure out why this won't work

         

abbeyvet

10:46 am on Sep 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Trying to do two things:
1. Limit number of rows displayed - this works
2. Limit or snip length of text displayed - this is not working.

Here is the code I am using:

// check start point and limit number of rows shown
$start = $_GET["start"];
$result = mysql_query("SELECT * FROM entries order by id desc limit 0,3");
$numposts = mysql_numrows($result);


// display entries if they exist.
if (mysql_numrows($result)!=0) {
while ($myrow = mysql_fetch_array($result)) {

// snip the entry
$snip = $myrow["entry"];
if (strlen($snip >= 80)) {
$snip = substr($snip, 0, 80);
$snip = trim(substr($snip, 0, strrpos($snip, ' '))).'...';
}

// display the item
echo "<p>".$myrow["title"]."<br>".$snip."</p>\n";

}
}

Can anyone see what is wrong there? Why is the snip not happening?

tomda

11:20 am on Sep 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Found one error.

if (strlen($snip >= 80))
should be
if (strlen($snip) >= 80)

// check start point and limit number of rows shown
$start = $_GET["start"];
$result = mysql_query("SELECT * FROM entries order by id desc limit 0,3");
$numposts = mysql_numrows($result);

// display entries if they exist.
if ($numposts!=0) {
while ($myrow = mysql_fetch_array($result)) {

// snip the entry
$snip = $myrow["entry"];
if (strlen($snip) >= 80) {
$snip = substr($snip, 0, 80);
$snip = trim(substr($snip, 0, strrpos($snip, ' '))).'...';
}

// display the item
echo "<p>".$myrow["title"]."<br>".$snip."</p>\n";

}
}

abbeyvet

11:55 am on Sep 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you :)