Needlessly complex. Also, shouldn't str_replace("\r"..) be done on input?
Signed-off-by:Joshua Dickerson <joshua.a.dickerson@gmail.com>