How to convert multiple tag to a single tag in php

You can do this with a regular expression:

preg_replace("/(<br\s*\/?>\s*)+/", "<br/>", $input);

This if you pass in your source HTML, this will return a string with a single <br/> replacing every run of them.

Leave a Comment