<?php
$var1 = 'var2';
$var2 = 'nameOfVariable';
$nameOfVariable = 'The value I want!';
echo $$$var1;
?>
And you can use curly brackets:
<?php
$var1 = 'nameOf';
$var2 = 'TheVariable';
$nameOfTheVariable = 'Another value I want!';
echo ${$var1 . $var2}; // Use concatenation to generate the variable name and then access it //
?>
this is really bad practice and with proper code you should not need that mutation of code.
also, don’t directly output $_POST/$_GET or $_REQUEST content without using htmlentities() around it, as your site might be vulnerable to cross-site-scripting and other injections.
Mind you can also do that with more $s:
And you can use curly brackets:
Mind you can also do that with more $s:
And you can use curly brackets:
no
Wow! I never even knew about this. Might be a pretty great asset in the future.
how? ^
I would like to ask a question, How to show variable in between the text.
E.g., I have
“var1 = $_POST['username'];”
I want to show it something like this,
“Hello [username]“.
How to do it?
I tried this but it didn’t work,
“echo Hello $var1;”
Please help me regarding this.
$var1=$_POST’username’];
echo “Hello [" . $var1 . "]“;
Try like this
$var=$_POST['username'];
echo ‘Hello['.$var.']‘;
If you need to create variables from an array there are two options.
The first uses php extract()
The second options which will give you more control is php list()
this is really bad practice and with proper code you should not need that mutation of code.
also, don’t directly output $_POST/$_GET or $_REQUEST content without using htmlentities() around it, as your site might be vulnerable to cross-site-scripting and other injections.