TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-21-2010, 02:16 PM   #1 (permalink)
The Acquainted
 
Join Date: Feb 2008
Posts: 107
Thanks: 3
CΛSTΞX is on a distinguished road
Default include in string ?

Hello,

Is it possible to include something in string or with function ? If not, how to do that ?
I have to make it in string. When I use the string, it should includes it.

$include = include("file/admin.php");
__________________
Downloadic
infolizer
Send a message via MSN to CΛSTΞX
CΛSTΞX is offline  
Reply With Quote
Old 06-21-2010, 03:21 PM   #2 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Wait, what?
You want to include that file into a variable? AFAIK it's not possible. But why would you want to do that?
__________________
Tanax is offline  
Reply With Quote
Old 06-21-2010, 04:01 PM   #3 (permalink)
The Acquainted
 
Join Date: Feb 2008
Posts: 107
Thanks: 3
CΛSTΞX is on a distinguished road
Default

My script's template system uses tpl files. In tpl files, you can only use $value. If you use include("file");
it would be bad because the included file contains appear at the very top of the page. I mean, how to include file instead of include("file.php");

is there anyway to include file with function or anything else ?
__________________
Downloadic
infolizer
Send a message via MSN to CΛSTΞX
CΛSTΞX is offline  
Reply With Quote
Old 06-21-2010, 04:37 PM   #4 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

you can use include to save the return content of a document. the manual gives an example:
php Code:
return.php
<?php

$var = 'PHP';

return $var;

?>

noreturn.php
<?php

$var = 'PHP';

?>

testreturns.php
<?php

$foo = include 'return.php';

echo $foo; // prints 'PHP'

$bar = include 'noreturn.php';

echo $bar; // prints 1

?>

if you want the whole content and not just the return value of the file, you can always use file_get_contents

Another thing you might want to get into account here, is the performance too, specially if they are big files. You don't want them all to be hold in the memory if they are big.
tony is offline  
Reply With Quote
Old 06-21-2010, 04:39 PM   #5 (permalink)
The Acquainted
 
Join Date: Feb 2008
Posts: 107
Thanks: 3
CΛSTΞX is on a distinguished road
Default

That is the point. Thank you.
__________________
Downloadic
infolizer
Send a message via MSN to CΛSTΞX
CΛSTΞX is offline  
Reply With Quote
Old 06-21-2010, 04:43 PM   #6 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

great, glad I could help. Sounds like you are trying to make an CMS or at least a templates system, good luck.
tony is offline  
Reply With Quote
Old 06-21-2010, 04:51 PM   #7 (permalink)
The Acquainted
 
Join Date: Feb 2008
Posts: 107
Thanks: 3
CΛSTΞX is on a distinguished road
Default

But wait. The file which I include isnt easy as much as only a string in it. It includes many functions and etc. How to make it return ?

Here is the file xcheaphotel.com/comments/talkphp.php
__________________
Downloadic
infolizer
Send a message via MSN to CΛSTΞX
CΛSTΞX is offline  
Reply With Quote
Old 06-21-2010, 05:41 PM   #8 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

I'm not fully sure I'm understanding so I hope I don't point you in the wrong direction; you might be interested in output buffering. Check out the following Output Control Functions, which will allow you to do something akin to the following;

php Code:
<?php

ob_start();
include( 'some/file.php' );
$somefile = ob_get_clean(); // Contents of the include are now stored in a variable which can be manipulated or echo'd at your mercy.
 

This is just a very rudimentary example but could be more on the right track?
delayedinsanity is offline  
Reply With Quote
Old 06-21-2010, 07:35 PM   #9 (permalink)
The Acquainted
 
Join Date: Feb 2008
Posts: 107
Thanks: 3
CΛSTΞX is on a distinguished road
Default

Yes! That works pretty nice. Thanks...
__________________
Downloadic
infolizer
Send a message via MSN to CΛSTΞX
CΛSTΞX is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Lenght of a string in Javascript with jQuery EyeDentify Javascript, AJAX, E4X 4 09-23-2009 10:00 PM
who can tell me why? kuigg Absolute Beginners 9 12-02-2008 02:14 AM
array elements into variables and values Dave Absolute Beginners 7 06-20-2008 01:56 PM
Quicker String Verification Jay Tips & Tricks 16 12-30-2007 01:47 PM
header VS include vuthcam General 12 11-14-2007 08:51 PM


All times are GMT. The time now is 11:36 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design