Jump to content

[SOLVED] Limited Characters


thomashw

Recommended Posts

SELECT paragraph FROM table WHERE whatever='whatever';

 

Select your stuff, then do this:

$shortened = substr(0, 100, $row['paragraph'])

$shortened .= '...';

echo $shortened;

 

 

Obviously, this is in the while loop from the mysql_fetch_array calls.

Try this:

 

<?php
$str = 'Long teeeeeeext';
$str = substr($str, 0, 100);
$dotPos = strrpos($str, '.'); //find last occurrence of "."
$str = substr($str, 0, $dotPos);
echo $str;
?>

 

The code will trim the text to 100 character, find the last occurrence of a dot and trim the text again, so u have full senteces. U can use the strrpos() for a space (" ") if u dont want to show full sentences.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.