Re: newlines to BR tag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You can use something like this ..

$new_str = preg_replace('/(\r\n){2,20}/', "\r\n", $old_str);

Amit
www.digitalamit.com

Murat Biyikli wrote:
if there are unknown number of newlines repeating like (\r\n\r\n\r\n) in a
post var and if I want to change them to a SINGLE newline, what kind of an
iteration should be used? The message may like below in DB and as you see
the \r\n newline codes may repeat severaltimes and should be changed to only
one SINGLE newline and after read from DB it will be easily coverted to BR
tag by nl2br($foo) func.

KIRKUK, Iraq (AP)\r\n\r\n - Iraqi engineers have fixed most of the damage
caused by a sabotage attack earlier this month on the main pipeline that
carries Iraqi oil to Turkey, but the country is still depending on a network
of substitute lines to export crude, an official with the North Oil Co. said
Monday. \r\n\r\n\r\n\r\n The official said 75 percent of the work has been
done but few more days are needed for the 40-inch pipeline to be ready for
exports to the Turkish port of Ceyhan. \r\nThe pumping rate is still down to
250,000 barrels a day from the normal average of 400,000 barrels, the
official said on condition of anonymity. Exports will go back to normal when
the line is fixed, he said.

SHOULD BE CHANGED LIKE (all new lines to a single newline):

KIRKUK, Iraq (AP)\r\n - Iraqi engineers have fixed most of the damage caused
by a sabotage attack earlier this month on the main pipeline that carries
Iraqi oil to Turkey, but the country is still depending on a network of
substitute lines to export crude, an official with the North Oil Co. said
Monday. \r\n The official said 75 percent of the work has been done but few
more days are needed for the 40-inch pipeline to be ready for exports to the
Turkish port of Ceyhan. \r\nThe pumping rate is still down to 250,000
barrels a day from the normal average of 400,000 barrels, the official said
on condition of anonymity. Exports will go back to normal when the line is
fixed, he said.

-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux