I was wondering if it were at all possible to include a variable from another page. Done some search engining, but nothing came up.
eg.
Code: Select all
include($var, "afile.php"); //include $var from afile.phpModerator: General Moderators
Code: Select all
include($var, "afile.php"); //include $var from afile.phpbecause its editable on the other page.jayshields wrote:Why include it? Just paste it into the file you want it or set it as a constant in the other file and refernence it that way.
You can't do that. Think of the include() function as a "copy and paste" of whatever is in the file being included into the script thats running at the position where the include() is called.iknownothing wrote:I was wondering if it were at all possible to include a variable from another page. Done some search engining, but nothing came up.
eg.the reason why is that want to include only one paragraph out of the page.Code: Select all
include($var, "afile.php"); //include $var from afile.php
ok, so can i include the entire file, but have it invisible, so i can "paste" only the variable...?onion2k wrote:You can't do that. Think of the include() function as a "copy and paste" of whatever is in the file being included into the script thats running at the position where the include() is called.iknownothing wrote:I was wondering if it were at all possible to include a variable from another page. Done some search engining, but nothing came up.
eg.the reason why is that want to include only one paragraph out of the page.Code: Select all
include($var, "afile.php"); //include $var from afile.php
You could do that with the output buffer I guess. It'd be a pretty awful hack though. Why not refactor the code so that it works properly? EG, put the variable you want into another file (better still, a database table) and include it in both the page you're working on at the moment, and the page it currently resides in.iknownothing wrote:ok, so can i include the entire file, but have it invisible, so i can "paste" only the variable...?
so does anyone know anything about this?? perhaps a character counter or something?iknownothing wrote: also with this, when the variable includes, it will be a reasonably long paragraph of text, and I was wondering how to add a "..." just before the end of its available area. Prime example being a search engine, when the desciption doesnt fit in.
Code: Select all
print( substr($var, 0, 50) . "..." );