Jump to content

How to include only variables?


chaking

Recommended Posts

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.