It can be done more than one way, if you want to use the strstr function insead, then this code works (it's your code, but you had a small typo): if (strstr($entered_field, "\n") || strstr($entered_field, "\r")) { $entered_field = preg_replace('[\r\n]+', ',', $entered_field); } PHP: