Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary spaces in PHP code #490

Closed
mrpavlikov opened this issue Jul 9, 2014 · 6 comments
Closed

Unnecessary spaces in PHP code #490

mrpavlikov opened this issue Jul 9, 2014 · 6 comments

Comments

@mrpavlikov
Copy link

I have some html file with php insertions:

<h1 class="content-page-header"><?=$view['name']; ?></h1>

After beautifying I use to have this:

<h1 class="content-page-header">
    <?=$view[ 'name']; ?>
</h1>

See that space right after [.

Also code like this:

<?= $view['content'][0]['descr']; ?>

becomes:

<?=$ view[ 'content'][0][ 'descr']; ?>

and ofc breaks syntax.

I seem to be unable to find the way to solve this. Is there any?

@evocateur
Copy link
Contributor

There probably is, but I'm not very familiar with the beautify-html script. The limitations of a non-parsing tokenizer really make handling templating syntax hairy.

@dboune
Copy link

dboune commented Apr 2, 2015

I believe the best option for this case, and other similar tickets here, is to allow beautify-html to leave the contents of <?= ... ?> and <?php ... ?> tags unformatted. I'm sure there may be other tags that could benefit from the same treatment. So far I have not found any existing setting sufficient to remedy this or other similar issues.

Should someone come along with a PR to handle PHP, wonderful, but until then the ability to ignore it would be extremely useful.

@bitwiseman
Copy link
Member

Agreed. Go for it!

@dboune
Copy link

dboune commented Jun 16, 2015

👏 Thank you!

@esetnik
Copy link

esetnik commented Apr 16, 2018

This is still happening for unclosed single quotes.

Example:

<a href='' onclick='doIt("<?php echo str_replace("'", "\\ ", $var); ?>  "); '>
                            Test
                        </a>
                
<?php include_once $_SERVER['DOCUMENT_ROOT'] . "/shared/helpModal.php";  ?>

Output:

<a href='' onclick='doIt("<?php echo str_replace("' ", "\\ ", $var); ?>  "); '>
                            Test
                        </a>
                
<?php include_once $_SERVER['DOCUMENT_ROOT '] . "/shared/helpModal.php";  ?>

Note that $_SERVER['DOCUMENT_ROOT '] will be broken after formatting.

@bitwiseman
Copy link
Member

@esetnik
Wow, that is bad. Please open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants