nl2el – A better alternative to PHP nl2br

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. 🙂

Shyam has written 29 articles

Shyam is senior full stack developer, who loves to explore new technologies and work on them. He's passionate about coding so can code 24/7. He uses PHP as a backend programming language.

He knows Laravel, MySQL, AngularJS, ReactJS, Redis, Kubernetes, Git, CodeIgniter, PHP, MVC pattern, Lodash, jQuery, VanilaJS, Teamcity and many other technologies and tools.

Shyam writes notes and hacks on his blog (https://shyammakwana.me). In spare time he can be found @ StackOverflow or crafting any new open source application.

Passionate Programmer and Meditator #PERIOD.