Reputation: 1
In this code
<?php print "value of a is $a" ?>
I need to print this statement as it how?
Upvotes: 0
Views: 142
Reputation: 11
If you want to print $a
and not the a variable's value, there are two ways:
Escape the $
: print "value of a is \$a";
Use single quotes instead
Everything in single quotes, including $something and special chars (newline \n, Unicode chars \uxxxx) are treated literally.
print 'value of a is $a';
Upvotes: 1
Reputation: 4128
Append with a dot, escape double-quoted strings with a backlash, or use single quotes and obviate the need for escaping.
Upvotes: 0
Reputation: 25435
If you want to include the variable in the string you must use single quotes like so
<? php print 'value of a is $a' ?>
Hope this helps.
Upvotes: 0
Reputation: 816334
PHP performs variable parsing in double quoted strings,
You can use single quoted strings.
So depending on want you really want, you can do
print 'value of a is $a';
which literally print the string 'value of a is $a'
(which does not make much sense).
Or you can use string concatenation to print the variable and it's value:
print 'value of $a is ' . $a;
which will print 'value of $a is 42'
(if $a = 42;
).
Upvotes: 1
Reputation:
If you want to print $a
and not the a
variable's value, there are two ways:
1. Escape the $
<?php print "value of a is \$a"; ?>
2. Use single quotes instead
Everything in single quotes, including $something
and special chars (newline \n
, Unicode chars \uxxxx
) are treated literally.
<?php print 'value of a is $a'; ?>
Upvotes: 0
Reputation: 74202
You could either use single quotes or escape $a
within double quotes with a \
.
Either:
<?php print 'value of a is $a' ?>
Or:
<?php print "value of a is \$a" ?>
Upvotes: 1
Reputation: 86346
use single quote if you don't want to print the value of variable
<? php print 'value of a is $a' ?>
Upvotes: 3