Print reserved PHP variables, in double quotes

0

I have worked constantly in single quotes, that I have completely forgotten the use of double quotes.

Today I had styles in a file, among others like this:

echo '#parent';

and I had to migrate to

echo "#parent";

And now how can I operate the reserved php variables in double quotes

$row = "www";
echo "base64_encode($row)";

In single quotes I did it in the following way:

$row = "www";
echo ''.base64_encode($row).'';
    
asked by Alejo 26.08.2018 в 21:35
source

2 answers

0

It can be done practically, doing the same, the difference is that double quote is added:

$row = "www.example.com";
echo "".base64_encode($row)."";

You can see the demo

Deputy source on varied use of double and single quote.

answered by 26.08.2018 в 21:59
0

On the basis of what you are trying to do:

<?php
$row = "www";
echo ''.base64_encode($row).'';

The direct equivalent with double quotes would be:

<?php
$row = "www";
echo "".base64_encode($row)."";

An empty string of single quotes, '' , can also be represented with double quotes, "" .

Even so the correct way (without unnecessarily concatenating empty strings) to do so would be:

<?php
$row = "www";
echo base64_encode($row);

This is because in your code with single quotes you are concatenating an empty string before and after the call to base64_encode() , being completely unnecessary to do so since echo can directly receive the output of base64_encode() without need to do nothing more.

Regarding the attempt you have made:

<?php
$row = "www";
echo "base64_encode($row)";

It is not possible to execute a function (or method) inside the double quotes. In the PHP documentation you can see that you can only interpret values of variables or properties of class.

    
answered by 27.08.2018 в 09:57