sorry but you are not providing enough information to tell you why that is happening.
PHP is a pre processing language, your user input must be getting to the php somehow, either by being passed as a GET or POST variable, or by being recalled from a database.
How is the $var variable being set? and how is it being read to generate your unwanted output?
Need to see all the code to figure that out, what you have provided isn’t enough.