I was used to use nl2br when showing some content with line brakes, but first time my requirement was to format that html code and applying some styles. So I was thinking about alternative of nl2br PHP function.
So, Here below is a simple and tiny function that accepts two arguments
1. Your text
2. HTML element you want to use.
nl2el – an nl2br Alternative
This function will add your own HTML element as well as you can give class name to it also. Thus this function can be used as an alternative of nl2br function. Hope this helps. 🙂