July 29th, 2000, 04:17 PM
I am in the process of making a "News Section" for my site. What I am trying to figure outis this; is there a way to have PHP count the amount of characters in the "article", and automatically create an "abstract" that is displayed on the front page?
Any insights wold be greatly appreciated.
July 30th, 2000, 10:01 AM
First you have to determine the maximum length you'd like for the abstract. Then, using substr(), you can grab that much of the string. Of course, this might be the middle of the word so you can use strrpos() to get the position of the last space. Then use substr() again to grab everything until that space.
// -1 because we don't want to return the space as well
You can call this like:
July 31st, 2000, 01:36 AM
Thanks! It worked beautifully, with the exception that the "-1" actually chopped of the last letter in the word. When removed though, it works like a charm.