-2

I have some HTML code in a file created by an online JS editor

<h1>Title</h1><p>Some text</p><p>Some text</p>

that is not easily readable offline. I'd like to split it like this with php, that is more readable

<h1>Title</h1>
<p>Some text</p>
<p>Some text</p>

I can make a string replace adding the newline after each closure, but if I save several times it adds newlines every time I save.

Do you have any suggestion?

Thank you.

P.S. the online JS editor is Summernote, maybe there is a config to work around this?

Gimbo
  • 97
  • 1
  • 8

2 Answers2

1

what you looking to is "unminify html",there is some online tools can do the work like:

Mohamed Sa'ed
  • 781
  • 4
  • 13
  • Do you know of any PHP script to do it? Thank you – Gimbo Jan 10 '18 at 14:24
  • @GiorgioBorgonovo Asking for third party scripts or off site resources are off topic in SO. I suggest that you try Google. – M. Eriksson Jan 10 '18 at 14:39
  • @GiorgioBorgonovo you can use php [DOM](http://php.net/manual/en/book.dom.php)-elements [parse HTML](https://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – Mohamed Sa'ed Jan 10 '18 at 15:00
0

Following the suggestions of Mohamed, I found Tidy.

Tidy comes with both a shell command (http://tidy.sourceforge.net/) and a PHP library (http://php.net/manual/en/book.tidy.php), both of them work very well and provide sereal tools to maintain HTML code.

Gimbo
  • 97
  • 1
  • 8