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 01-19-2011, 02:22 AM   #1 (permalink)
The Visitor
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
kuujo is on a distinguished road
Default echo and file_get_contents

Two files:

test.php

Code:
$text

index.php

Code:
<?php
      $text = "something";
      $new = file_get_contents('test.php');
      echo $new;
?>
When I go to index.php it displays "$text", while I want it to display "something".

I'm trying to make simple template system, but when I try to read my templates with the above method, it displays php variables, not their values..
kuujo is offline  
Reply With Quote
Old 01-19-2011, 03:39 AM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

try this:

test.php
php Code:
test

index.php
php Code:
<?php
$test = 'something';
$new = trim(file_get_contents('test.php'));
$echo $$new,"\n";

that should work, because of how PHP look up variables and it lets you declare variable variables
tony is offline  
Reply With Quote
Old 01-19-2011, 10:11 AM   #3 (permalink)
The Visitor
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
kuujo is on a distinguished road
Default

That doesn't seem to work.

I'll explain some more.. I have some template files, that look like this:

HTML Code:
<div>
  <div id="left">{ value1 }</div>
  <div id="right">{ value2 }</div>
</div>
I also have template.php, which has function to change the { some_value } to $some_value.

In index.php I did:

PHP Code:
$new replace_keywords(file_get_contents('content/main.tl'));
echo 
$new
And I get all the names of $some_value, but not their values.

I tried your method, but it didn't work.

However.. I tried using eval and it worked. But I heard that it is not good to use eval, so what's the best solution for this?
kuujo is offline  
Reply With Quote
Old 01-19-2011, 12:30 PM   #4 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

I believe in KISS (Keep It Simple, Stupid!)
PHP Code:
$test 'Something';
ob_start();
include 
'content/main.tl';
echo 
ob_get_clean(); 
This method would require your template file to have and echo also:
PHP Code:
<?php echo $test?>
You could also faff around and make some kind of smarty type thingy, personally I think its a waste of time and resources, but hey hum.

PHP Code:
$test 'something';
echo 
str_replace('$test'$testfile_get_contents('content/main.tl')); 
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 01-19-2011 at 12:30 PM. Reason: speeelinnnk
sketchMedia 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


All times are GMT. The time now is 06:29 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