Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is VS Code removing closing tag ?> on save. anyone knows?

Tags:

php

tags

when i save my php file then VS Code removes ?> tag from ending. and its causing problems in execution. I dont know why is this happening. If anyone knows please help. Thank u.

Update: I was using Es-lint and Prettier extensions at the same time. I removed them and now its fine.

like image 260
Single-byte Avatar asked Nov 15 '25 00:11

Single-byte


2 Answers

End tag removal is covered here in detail: PHP end tag "?>" It's recommended practice for pure PHP files.

like image 146
Ahmad Avatar answered Nov 17 '25 19:11

Ahmad


I find two ways to solve this problem.

  1. Go to VSCode settings and in the search bar type "format", then uncheck Editor: Format on save. Formatting the code will no longer work, but VSCode will also not delete the PHP closing tag.

  2. Install the php cs fixer extension and I hope it will solve the issue.

like image 21
Vukasin Avatar answered Nov 17 '25 19:11

Vukasin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!