I understand you
It’s frustrating to see our code all messed up:D
Need indentation in HTML output?
You really don’t need.
Makes a difference to the execution of the code?
Dude if you care about every bit that runs, then you need to worry about the blanks.
Or if you have a very large execution, it will weigh on the processing.
Someone’s gonna see that beautiful code?
If you look at the source code... Yes!
Looks good?
If you care about the presentation of the code, it will look beautiful!
Something positive?
- You will feel good to have an easy-to-read HTML and without that sausage code ZONE.
- When someone goes to look at your code you will see that you have cared about it and you will realize that if you even care about it for when someone goes to look, then you will worry about more important things.
- Recruiters often look at code output to see if the professional is organized.
I know how you must feel. Without further ado.
You can use the HEREDOC
When I want an organized output of my HTML that will be written by PHP I do so:
<?php
echo <<<'HTML_EXEMPLO_PODE_SER_QUALQUER_NOME_AQUI'
<h1> Precisa Olhar como ficou no comsole do Chrome </h1>
<br>
<p>
<a href="#">Testando</a>
<p/>
<br>
bem aqui, nessa posição, sem bagunça
HTML_EXEMPLO_PODE_SER_QUALQUER_NOME_AQUI;
?>
To see an example working online go to the following link and click the Run Code button, it’s the same code I put above.
http://sandbox.onlinephpfunctions.com/code/7d0a80bbca28482554af71f877fe643c21b0ea76
use alternative syntax in these cases: https://www.php.net/manual/en/control-structures.alternative-syntax.php
– André Walker
First, it makes no sense to indent PHP within HTML, the indentation of PHP should be relative to PHP itself (i.e., its first code is poorly indented). And for HTML to come out right just put the indentation in echo. Example:
echo "\t\t\t<p>estou indentado</p>\n";
- Three tabs and a line break in HTML (has a lot of ways. For large snippets can have HEREDOC and NOWDOC instead of echo, for example).– Bacco
@Bacco Depending on the case (pq this author code probably isn’t even the one from the question) will probably solve better using only
<a href="<?="variavel ou algo aqui";?>"><?="variavel ou algo aqui";?></a>
and leave the indentation in the HTML itself– Guilherme Nascimento
@Guilhermenascimento artificial example gives this, can not know or what is the problem actually has to solve (but anyway, indenting the PHP chunk by HTML never makes sense)
– Bacco