$contents = preg_replace("/[\r\n]+/", "\n", $contents); The + quantifier tells the pattern matcher to repeat the previous item once or more. So it'll grab all of the extras in a row and replace them with one.
remove multiple line in php from string
July 18, 2023 in Php