Skip to content
Advertisement

split each HTML tag into new line using PHP

I’m going to split each HTML tag into a new line. This is my source:

JavaScript

And I’m gonna have it like this:

JavaScript

or like this:

JavaScript

And this is what I’ve done:

JavaScript

and this is the output with put each “>” in a separate line (array member).

JavaScript

Advertisement

Answer

Instead of using a regex and splitting your source into an array, you could use the str_replace() function to replace > / < with a > / < and a newline. See PHP documentation

This should work fine:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement