954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Echo php code and not the variable.

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.

Who me?
Newbie Poster
6 posts since Aug 2011
Reputation Points: 10
Solved Threads: 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;

?>
Gromit
Posting Whiz in Training
212 posts since Sep 2008
Reputation Points: 47
Solved Threads: 31
 

Thank you,

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

Who me?
Newbie Poster
6 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: