My source code here
<?php
$a = "$b = dfsdf ";
echo $a;
?>
I want to get out put result as below
$b = dfsdf
My source code here
<?php
$a = "$b = dfsdf ";
echo $a;
?>
I want to get out put result as below
$b = dfsdf
use single quote instead of double quotes i.e. $a = '$b = dfsdf';
OR
$a = "$\b = dfsdf";
echo stripslashes($a);
Read about the difference in single and double quotes. You need to use single quotes here:
$a = '$b = dfsdf ';
echo $a;
See the manpage on strings:
https://www.php.net/manual/en/language.types.string.php
You can use an escape sequence for special characters when using double quotes. In your case Php is attempting variable substitution ($b
is likely parsed to an empty string and will not show as $b
, this should also emit a Php notice.)
Escape the dollar like so:
echo "\$foo = bar";
You can use single quotes:
echo '$foo = bar';
Ideally you want to use a Nowdoc:
From the manpage above:
no parsing is done inside a nowdoc. The construct is ideal for embedding PHP code or other large blocks of text without the need for escaping.
echo <<<'PHP'
$foo = bar
PHP;
Output for each of these:
$foo = bar
Rather than echoing directly, you can of course assign in the same manner to a variable.
Note that $foo = bar;
is a bad code sample, as the bar likely should be quoted.
This might be the solution you are looking for. Replace double qoutes with single one. As single qoutes assigns as it things given inside of it.