Break line after the img tag with RegEx

1

Colleagues.

I'm not very knowledgeable about regular expressions, however, I need to know that after the < img > break a line. For example:

  

$ string="< img src = 'images / image.jpg' > here will be the line break";

It would look like this:

  

(the image)
here there will be the line break

    
asked by anonymous 08.05.2016 / 00:41

1 answer

3

Follow RegEx:

preg_replace( '/(<\s*img.*>)/U', "$1<br>\n", $string );

See working at IDEONE .


I'm only concerned about helping you make the site complicate for nothing, because the cause of the problem seems to be the data in the DB in an unsuitable format.

It is suggested to treat the data when writing to the DB, not the time to show on the screen. Better still, it would be if you made a special markup for your posts, and already create the tags and the layout from there (as does Markdown, for example).

    
08.05.2016 / 00:51