Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Putting a variable between double quotes before echoing?

Tags:

php

Now and then I'll see code like

$str = strip_tags($str)
echo "$str";

Does that do anything at all? Why put the variable in quotes instead of echoing it directly?

like image 452
beardedlinuxgeek Avatar asked Dec 10 '25 23:12

beardedlinuxgeek


1 Answers

It's just a terrifically common misunderstanding of new (PHP) programmers. It happens to work exactly the same as not quoting the variable at all, but is entirely superfluous. I'd love to know as well why people think this is necessary; but one can see it surprisingly often.

like image 197
deceze Avatar answered Dec 12 '25 12:12

deceze



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!