$el = ""; foreach(preg_split("~[\r\n]+~", $el) as $chunk){ $el .= "<p>" . htmlspecialchars($chunk) . "</p>"; };