Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto Format HTML/PHP With Line Breaks and Tabs [closed]

Tags:

html

php

I've run into a problem. Someone on our team edited a HTML/PHP file, and the entire contents of the file ended up on a single line. All line breaks and tabs were completely removed from the file. Its a very large file, so trying to edit it manually would take forever.

Does anyone know of a tool I can use to re-format the code?

like image 991
mellowsoon Avatar asked Jun 29 '11 05:06

mellowsoon


4 Answers

Use the NetBeans IDE, for the development purpose. Then open the file in that IDE and press these keys at the same time - Alt + Shift + F.

The file will get formatted nicely, and also will show you if there are any errors in that file.

like image 182
Knowledge Craving Avatar answered Nov 06 '22 02:11

Knowledge Craving


You could use DOMDocument to tidy the HTML.

$dom = new DOMDocument();
$dom->preserveWhiteSpace = FALSE;
$dom->loadHTML($html);
$dom->formatOutput = TRUE;

echo $dom->saveHTML();
like image 43
alex Avatar answered Nov 06 '22 04:11

alex


You can use tidy (html only) or codecleaner

like image 22
Ravan Scafi Avatar answered Nov 06 '22 02:11

Ravan Scafi


(First link removed per comment below.)

http://www.phpformatter.com/ is an option.

like image 4
Amber Avatar answered Nov 06 '22 02:11

Amber