phpregeximagemultilinesanitization

Remove excess newlines/whitespace from multi-line <img> tag in HTML string


How could I remove all the new lines from all img tags. So for instance if I have:

$string = '<img
           src="somelong
            pathimage.jpg"
             height="1" width="10">';

so it looks as:

$string = '<img src="somelongpathimage.jpg" height="1" width="10">';

Solution

  • $string = preg_replace("/\n/" , "" , $string);