![]() |
$content = include('file2include.php');
Well I tried something funny some days ago - include a file with include and put it in a variable :-)
file2include.php PHP Code:
PHP Code:
Now what I get in the Browser is: HTML Code:
<table>(This thread is not about - if we should use something like that above or not ;-) ) |
include comes back as a boolean
|
If the file has been included successfully, and there is no
return statement in the included file, $content will be an integer 1. If the file returned something, then $content will be that value. If the file could not be included for whatever reason, then $content would be a boolean FALSE and an E_WARNING would be issued. |
lol, sorry for an dumb question like that, but I got a code like that
PHP Code:
changed it now to PHP Code:
|
In a more learning purpose.. How would you get the content of a PHP file(with the PHP intact), and assign in to a variable? Is that even possible?
|
Quote:
|
It is possible with
file_get_contents and eval if you wish to execute the code, too. If nobody else has posted the code for you by the time I get my laptop back, I will write an example :-) ! |
No idea how wildhoney wants to go with eval - but you can do it like:
PHP Code:
PHP Code:
HTML Code:
<html>Edit: sorry forgot to explain what happens actually: PHP Code:
|
ARGH, just read the post above sigh :'-(
Long day. |
@Saka why would you do all that?
I usually just say include (...) |
Well as I said it was not my code -and I changed it later on to just "include" - but you could use for something like:
We want to build an small login widget. The html code is somewhere in an extra html file, and we are currently in a class which builds the sidebar widgets. Now we dont want to "echo" the code when it is executed since we still have some other html which goes first (<head></head><body> etc.). So we could go, copy the content in our variable - and include it anywhere in our site. Well, it might not be the best example - but I cannot think of any better atm :-D |
That lost me...
If you had a function that spit out a your login/join box, you would say: PHP Code:
PHP Code:
|
| All times are GMT. The time now is 08:48 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0