chaking Posted February 22, 2008 Share Posted February 22, 2008 I have a file I'm trying to: include "update.php"; update.php has some echo statements if it functions properly, but it also sets the values of a lot of variables. when I include update.php into update2.php, all the variables are passed very nicely, but it also prints out the rest of update.php (I have a form in update.php, so everytime I run update2.php it prints the update.php form AND the update2.php form)... Basically, is there a way to only include the variable values in update2.php instead of the whole file? Link to comment https://forums.phpfreaks.com/topic/92385-how-to-include-only-variables/ Share on other sites More sharing options...
drisate Posted February 22, 2008 Share Posted February 22, 2008 <?php //us a var is update.php if (isset($forme_should_not_be_posted))[...] ?> Link to comment https://forums.phpfreaks.com/topic/92385-how-to-include-only-variables/#findComment-473319 Share on other sites More sharing options...
chaking Posted February 22, 2008 Author Share Posted February 22, 2008 right, I understand how to include a file. My question is: Is there a way to only include variables from a file instead of all the code? Because when I include all of the code from that file, it shows the form I created in the included file on the new page. ---OOps, ok you updated your response while I was responding. So the isset function merely checks if the variable is already in use, correct? I don't have a problem with passing the variable's value, I have a problem with the rest of the code of the included file being displayed in my final result. Link to comment https://forums.phpfreaks.com/topic/92385-how-to-include-only-variables/#findComment-473322 Share on other sites More sharing options...
phpSensei Posted February 22, 2008 Share Posted February 22, 2008 You can define a CONSTANT $data = "this is the data"; define("data",$data,true); part 2 include("part1.php"); define("data",true); echo data; Link to comment https://forums.phpfreaks.com/topic/92385-how-to-include-only-variables/#findComment-473324 Share on other sites More sharing options...
chaking Posted February 22, 2008 Author Share Posted February 22, 2008 thanks phpsensei - I thought I might have to go that route. Link to comment https://forums.phpfreaks.com/topic/92385-how-to-include-only-variables/#findComment-473325 Share on other sites More sharing options...
duclet Posted February 22, 2008 Share Posted February 22, 2008 Though I don't recommend doing this, you can try something like the following: <?php ob_start(); include 'update.php'; ob_end_clean(); // The rest of your update2.php file ?> This will include the code of update.php but because of the output buffer, the output of update.php won't be shown. We use ob_en_clean to terminate the output buffer without outputting anything. Link to comment https://forums.phpfreaks.com/topic/92385-how-to-include-only-variables/#findComment-473327 Share on other sites More sharing options...
chaking Posted February 22, 2008 Author Share Posted February 22, 2008 duclet: That was it! perfect! Link to comment https://forums.phpfreaks.com/topic/92385-how-to-include-only-variables/#findComment-473343 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.