eslame
eslame

Reputation: 1

how i can print the variable as it not the value of the variable

In this code

<?php print "value of a is $a" ?>

I need to print this statement as it how?

Upvotes: 0

Views: 142

Answers (7)

Ahmed Soltan
Ahmed Soltan

Reputation: 11

If you want to print $a and not the a variable's value, there are two ways:

  1. Escape the $: 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.

print 'value of a is $a';

Upvotes: 1

Wolfpack&#39;08
Wolfpack&#39;08

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

Ash Burlaczenko
Ash Burlaczenko

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

Felix Kling
Felix Kling

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

user492203
user492203

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

Alan Haggai Alavi
Alan Haggai Alavi

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

Shakti Singh
Shakti Singh

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

Related Questions