How do I remove multiple blank lines from a string.
I have looked at the examples on stackoverflow and have tried to change my code accordingly but I am not getting the right answer.
function removeMultipleBlankLines(&$array)
{
$value = $array;
$value = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $value);
return $value;
}
$textarray=array("The red","big"," "," ","fox","is ready","","","to jump.");
echo print_r(removeMultipleBlankLines($textarray));
You can do:
to get exactly what you want.
Here is link to php’s docs page about
trimfunction, which does the job.