I am currently developing a CMS and want to add in the functionality of limiting an excerpt of text by its line length. Say I want to control the display of text and ensure all blocks are the same height by controlling the amount of lines of text that show.
Does any know of any pre-written function or perhaps article to help get me started? It would gratefully be appreciated. Thank you.
You can use the native
wordwrap()function to control how many characters are permitted per line. This function would also permit you to limit the number of lines you would like to show as well by exploding the results on the break-sequence, and gluing together any number of the resulting array values.Here I have limited each line to 25 characters, at most. I’ve then taken the first two lines and printed them out, one after another.
Demo: http://codepad.org/8aCusZGQ