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
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.

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.