How can I pass a variable to an interpreted file?

cade galt

So I have a case were I need to interpret a PHP file and then put it in a variable as a string.

I have this some what common helper function to do this:

function ob ($path) {
    ob_start();
    include($path);
    $string = ob_get_contents();
    ob_end_clean();
    return $string;    
}

Just give it the path and it will give you the string after it has been interpreted. Works great.

However I also need to send it a variable. I tried just appending a GET request string to the path, but it appeared not to work. The function prototype would look like this:

// how would I implement this?
function ob ($path, $variable_to_send) {  
}

How should I do this?

user2258887

Simply use a global variable.

Set it in one file like this:

$GLOBALS['arg'] = 'test';

Access it in another file similarly:

$arg_passed = $GLOBALS['arg'];

If you wanted to architect this a bit more use the registry pattern.

Note this assumes that this is the same HTTP request. If you need persistence across HTTP requests use session variables.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I pass in text rather than a file as a variable

From Dev

How can I pass in text rather than a file as a variable

From Dev

Can I pass variable to required file?

From Dev

how can i pass variable in parameter as a function?

From Dev

How can I pass a variable to spreadsheet function?

From Java

How can I pass arguments to a batch file?

From Dev

how can i pass js variable to php variable?

From Dev

how can I pass variable i in linearSearch function?

From Dev

How can I print a variable to a file?

From Dev

How can I store my variable in a file?

From Dev

How can I provide garbage collection for an interpreted language implemented in C?

From Dev

How can I pass a Razor boolean variable to an Angular directive?

From Dev

How can I pass a Laravel variable into my AngularJS view?

From Dev

How can I pass javascript variable to grails controller using remoteFunction

From Java

How can I pass a type or variable to this is_same function?

From Dev

How can I pass a smarty variable to a php function?

From Java

How can I pass variable to ansible playbook in the command line?

From Dev

How can I pass argument stored on a variable to WGET

From Dev

How can I pass a Django template context variable to JS function

From Dev

How can I pass a shell script variable into an Expect script?

From Dev

How can I pass a variable value from one sub to another

From Dev

How can I pass a php variable to another form in the same page?

From Dev

Python pandas, how can I pass a colon ":" to an indexer through a variable

From Dev

How can i get variable from listview and pass to another activity?

From Dev

How can I pass variable from one function to another in angularJS?

From Dev

How can i pass a variable and some HTML using jQuery .html()

From Dev

How can I do to pass variable throught the modals?

From Dev

How can I pass argument stored on a variable to WGET

From Dev

How can I pass variable in pthread_cond_signal function?

Related Related

  1. 1

    How can I pass in text rather than a file as a variable

  2. 2

    How can I pass in text rather than a file as a variable

  3. 3

    Can I pass variable to required file?

  4. 4

    how can i pass variable in parameter as a function?

  5. 5

    How can I pass a variable to spreadsheet function?

  6. 6

    How can I pass arguments to a batch file?

  7. 7

    how can i pass js variable to php variable?

  8. 8

    how can I pass variable i in linearSearch function?

  9. 9

    How can I print a variable to a file?

  10. 10

    How can I store my variable in a file?

  11. 11

    How can I provide garbage collection for an interpreted language implemented in C?

  12. 12

    How can I pass a Razor boolean variable to an Angular directive?

  13. 13

    How can I pass a Laravel variable into my AngularJS view?

  14. 14

    How can I pass javascript variable to grails controller using remoteFunction

  15. 15

    How can I pass a type or variable to this is_same function?

  16. 16

    How can I pass a smarty variable to a php function?

  17. 17

    How can I pass variable to ansible playbook in the command line?

  18. 18

    How can I pass argument stored on a variable to WGET

  19. 19

    How can I pass a Django template context variable to JS function

  20. 20

    How can I pass a shell script variable into an Expect script?

  21. 21

    How can I pass a variable value from one sub to another

  22. 22

    How can I pass a php variable to another form in the same page?

  23. 23

    Python pandas, how can I pass a colon ":" to an indexer through a variable

  24. 24

    How can i get variable from listview and pass to another activity?

  25. 25

    How can I pass variable from one function to another in angularJS?

  26. 26

    How can i pass a variable and some HTML using jQuery .html()

  27. 27

    How can I do to pass variable throught the modals?

  28. 28

    How can I pass argument stored on a variable to WGET

  29. 29

    How can I pass variable in pthread_cond_signal function?

HotTag

Archive