If you are trying to do a page, or section of news that only shows a certain length of characters, and then has a link for Read Full Story, or more..., etc the following code is just what you need:

$longtext = "Full text string to be manipulated";
// I want mine to cut off text after 255 chars
$shorttext = substr($longtext,0,255);	
$space = strrpos($shorttext," ");
$newtext = substr($shorttext,0,$space);
echo "$newtext <a href=more_details.php>more...</a>";

Note: I'm posting a few of these code snippets just for general reference. They are somewhat old, so please feel free to make updates, suggestions for this code. I'm posting them mainly for the benefit of newer PHP programmers. :)

After I get settled in, and have a little more time, I'll make updates to these next few threads, and sit down, and put together some tutorials that are more up to date.

Recommended Answers

All 2 Replies

i think this can be done by spliting and then just show the first 10 words or something like that i bet there is a easier way tho

commented: 6 year bump, really? -2

i think this can be done by spliting and then just show the first 10 words or something like that i bet there is a easier way tho

6 year bump, new record! I think that qualifies for drinking an entire case!

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.