Solution 1: Line Conversion Techniques
You can remove unnecessary content or line breaks between HTML
tags using several approaches.
Approach 1: Remove Anything Between
Tags Using Regex
$str = preg_replace("/(\/[^>]*>)([^<]*)(<)/", "\\1\\3", $str);
This strips anything between closing and opening
tags, including newlines, whitespace, or text.
Example:
<p>Text</p>
<p>More text</p>
Approach 2: Remove Only Line Breaks and Newlines Using Regex
$str = preg_replace("/[\r\n]*/", "", $str);
Approach 3: Remove Line Breaks Using str_replace()
$str = str_replace(array("\r","\n"), "", $str);