I had somone create a function for me to the following specs a couple months ago:
Take some text (usually with html tags) and return the text trimmed & cleaned as necessary given the parameters.
function sendValidText($txt, $max_length, $length_criteria, $max_links)
// $txt = the original article text for the particular article field
// $max_length = the maxumum length the particular article directory allows for this field
// $length_criteria = "word" or "char" depending on whether the length is a word or character limit
// $max_links = the maxumum amount of hyperlinks allowed in the txt
// given the above parameters, return the $txt trimmed as necessary
// count any html tags along with text when determining word or character count
// if a trim is needed, trim at *sentence boundaries*...
// So if you are 30 characters into a new sentence and it then exceeds the limit, remove the entire sentence.
// but if removing the entire sentence would result in there being no text left in $txt,
// then instead trim at a word boundary, and put "..." after it
// (making sure the "..." doesn't exceed limit)
// if the max_links are exceeded, remove random links to pull it back to the maximum.
// but make sure a trim doesn't take place in the middle of the following html tags: "a, b, strong, em, i".
Everything has been working fine for a month or so with this function, but now there is some text that is throwing my function into a continuous loop.
I need someone to fix the function so that at the very least it will catch the continuous loop and throw an error... but it should actually fix the problem and return the right text.
I can send you a link to the function and problem text via the messageboard if you're interested in taking a look and bidding.