Save and maintain indentation

In my PHP files I have lots of indentation. All of a sudden, relatively recently, I lose my indentation every time I save and re-open my PHP file.

I save a file with this sort of code:

echo('<div class="maintext">');
echo('<h2>Cookies Info</h2>');
echo('<div class="txt">Cookies explanation</div>');
echo(<div class="txt">Further explanation</div>');
echo('</div>');

echo('<div class="maintext">');
echo('<h2>Cookies Usage</h2>');
echo('<ul>');
echo('<li>Example one</li>');
echo('<li>Example two</li>');
echo('<li>Example three</li>');
echo('</ul>');
echo('</div>');

I save my file and I open it again with PHPStorm and I have:

echo('<div class="maintext">');
echo('<h2>Cookies Info</h2>');
echo('<div class="txt">Cookies explanation</div>');
echo(<div class="txt">Further explanation</div>');
echo('</div>');

echo('<div class="maintext">');
echo('<h2>Cookies Usage</h2>');
echo('<ul>');
echo('<li>Example one</li>');
echo('<li>Example two</li>');
echo('<li>Example three</li>');
echo('</ul>');
echo('</div>');

I then go back and redo the indentation. But when I save and re-open my file most of the indentation is lost when I open the file. Most frustrating!

I have tabs set as 4 spaces.

Help!

0
1 comment

Hi there,

Check what you have at "Settings/Preferences | Tools | Actions on Save" -- you may have "Reformat Code" action enabled.

 

P.S. It's offtopic, but why use that many echo here (one per tag/block)? If it's your code consider looking into using HEREDOC/NOWDOW -- you will have an easier maintenance experience with multiline blocks than the current one (IMO of course, unless there is something else that I'm missing)...

echo <<<HTML
<div>
<div>inner</div>
</div>
HTML;
0

Please sign in to leave a comment.