Question is simply easy, but it seems I can't find solution so..
I'm getting html string from file using:
ob_start();
require_once 'view/form.php';
$html = ob_get_contents();
ob_end_clean();
And it works, then I'm putting this string in text box using
echo '<br /><textarea style="width:100%" rows="10">'.$html.'</textarea>';
But html goes out messy with lots of white spaces and tabs, is there a way to format it in decent way to be more readable?
You can use Tidy (or any other HTML prettifier) to prettify HTML.
ob_start();
require_once 'view/form.php';
$html = ob_get_contents();
ob_end_clean();
$config = array('indent' => TRUE, 'output-xhtml' => TRUE);
$prettyhtml = tidy_parse_string($html, $config, 'UTF8');
But please do take a look at the link provided, to see a cleaner, more thorough example.
This requires the tidy extension to be installed with your php install. On Ubuntu, you can install it using apt-get install php5-tidy
. If installing extensions is not a possibility, do a quick search for 'php html prettify', and I'm sure you'll be able to find a prettifier class you can include, such as htmLawed.
If you want to display the HTML in your textbox, make sure you escape it before echoing it, so it's not actually interpreted as HTML in the browser.