How to remove empty lines from string using php using preg_replace function with regex pattern?

How to remove empty lines from string using php using preg_replace function with regex pattern?

Just use preg_replace php function

preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $string);

done