Member Avatar

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.

Recommended Answers

All 2 Replies

Hello Who?!

Does something like this help?


// 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;

Member Avatar

Thank you,

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.