I have a variable (ex. $content) with HTML code (without line breaks – removed before). How to process HTML code with adding TAB indent after each open tag and decrease indent level after each closing tag?
P.S. I don’t need external script or programm (like tidy). I need to make this in my own script.
For example:
source content:
<!DOCTYPE html><html><head><title>test</title></head> <body> <h1>hello!</h1><p>It works!</p></body></html>
needed result:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<h1>hello!</h1>
<p>It works!</p>
</body>
</html>
1 Answer