0

How can I use a variable to create another variable so that the output is not the content of the new variable but the php code for the new variable?

For example:

If variable $a = "house"
and the name of the final variable is $b,
then how do I produce variable $c so that the result of echoing $c is the php code:

<?php $b = "house"; ?>

The context is that I am using one file to write another file. The second file needs to contain the line, <?php $b = "house"; ?>, which has been constructed by variable $c in the first file.

I appreciate the help.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Who me?
0

Hello Who?!

Does something like this help?

<?php

// set $a to house here:
$a = "house";

// set $c to the php code we want, using
// $a as a variable:
$c = "<?php \$b = \"$a\"; ?>";

// echo $c to see what out output looks like!
echo $c;

?>
0

Thank you,

This works. Really appreciate the help. It had me stumped for days.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.