Optimization of old code considered dangerous.

I originally wrote the RSS feed parser in an amazingly stupid manner. I don’t like the idea of an entire post being syndicated within a description – sure, it’s easy, but that’s just wrong. I don’t want to wade through 50k of someone’s livejournal tests.

My inital code created an array the size of the description text, broke a line at the end of a line – near a user-specified mark, got a list of the number of lines, then would iterate through them for a certain number, appending a little ‘more’ subtext at the end.

Here is it’s successor, in all of it’s haphazard glory..

The str_replace removes the invalid break tags from it, and this way I don’t need to worry about CR, CR+LF, etc storage on different platforms. Note that the execution of these subfunctions is very important! ;)

$myContent = “” . str_replace(“
”, “”, nl2br(trim(htmlspecialchars(strip_tags(stripslashes(substr($myContent, 0, $size_len))))))) . ” [more…]
”;