Am not sure if you tested your `PHP` code but your regex is wrong (It returns empty values)
http://codepad.viper-7.com/1MFTAW
You can also improve the php function by using nl2br and isset instead of in_array
Here is a revised code : http://codepad.viper-7.com/4OtoTD