I'm trying to make spelling corrections in a paragraph. One example of what I am doing is changing "im" to "I'm". I'm using preg_replace to do this. Within the code, I'm doing this "/ im /i", as opposed to this "/im/i", so that I do not end up changing words like slim to sl I'm. Sometimes this code works beautifully and at other times, sometimes at the beginning of a sentence it does not recognize im and does nothing. Any thoughts?
$text = preg_replace("/ im /i", " I'm ", $text);