ztealmax Posted December 18, 2006 Share Posted December 18, 2006 hi now im trying to do this:im opening a text file and it reads whats inside it in this case its "svenska"so now i want my script to include the file named language/svenska.php with this code, but cant figure out what i did wrong ;)Opens via addres bar:[b]language.php?language=config/language.cfg[/b][code]<?php$file = $_GET['language'];$fh = fopen($file, 'r') /*or die('Could not open file!')*/;$data = fread($fh, filesize($file)) /*or die('Could not read file!')*/;fclose($fh); ?><pre><? echo $data;?><?PHP require_once(language/$data.php); ?><? echo test ?></pre>[/code]the line [b]<? echo $data;?>[/b] works it prints out the correct content of the file!//Martin*** will show you all, soon what trying to do ;) *** Link to comment https://forums.phpfreaks.com/topic/31069-solved-include-files-from-data-lt-include-dataphp-gt/ Share on other sites More sharing options...
btherl Posted December 18, 2006 Share Posted December 18, 2006 What happens when you run this script? Link to comment https://forums.phpfreaks.com/topic/31069-solved-include-files-from-data-lt-include-dataphp-gt/#findComment-143443 Share on other sites More sharing options...
ztealmax Posted December 18, 2006 Author Share Posted December 18, 2006 [quote author=btherl link=topic=119071.msg487159#msg487159 date=1166427747]What happens when you run this script?[/quote]It opens up the file called language.cfg inside it i got one line of test that says "svenska"it echos it out to browser:but i need to get it to include the line svenska in the <? include ?> thingy Link to comment https://forums.phpfreaks.com/topic/31069-solved-include-files-from-data-lt-include-dataphp-gt/#findComment-143445 Share on other sites More sharing options...
btherl Posted December 18, 2006 Share Posted December 18, 2006 Does it give any errors or does it just not include the file? Link to comment https://forums.phpfreaks.com/topic/31069-solved-include-files-from-data-lt-include-dataphp-gt/#findComment-143446 Share on other sites More sharing options...
ztealmax Posted December 18, 2006 Author Share Posted December 18, 2006 it just doesnt include filei think i have done something wrong with the include line[b]<?PHP require_once(language/$data.php); ?>[/b]Im not sure it suppose to look that way ;)the line:[b]<? echo test ?>[/b] echos out whats in the include file svenska.php that i am trying to include with that Link to comment https://forums.phpfreaks.com/topic/31069-solved-include-files-from-data-lt-include-dataphp-gt/#findComment-143447 Share on other sites More sharing options...
ztealmax Posted December 18, 2006 Author Share Posted December 18, 2006 Okej to explain more in detail what i need it to do, or as i wanted it to do ;)[b]first we open a file for reading:[/b] (Via the browser)[code]x.php?language=config/language.cfg[/code][b]then we check what is written inside it:[/b] (In this case content of file is the word "svenska"x.php[code]<?php$file = $_GET['language'];$fh = fopen($file, 'r') /*or die('Could not open file!')*/;$data = fread($fh, filesize($file)) /*or die('Could not read file!')*/;fclose($fh); ?>[/code][b]now i want to include a filename from the data inside the document like this[/b] (svenska)[code]<? require_once("languages/svenska.php"); ?>[/code]but as i want to be able to use it in other languages to i need it to include the filename from the @datasomething like this:[code]<? require_once("languages/($data).php"); ?>[/code] (how ever it doesnt work, i need some help with figuring out what to do so it includes the file name stored in the $data [b]svenska[/b].php (in this case) Link to comment https://forums.phpfreaks.com/topic/31069-solved-include-files-from-data-lt-include-dataphp-gt/#findComment-143481 Share on other sites More sharing options...
trq Posted December 18, 2006 Share Posted December 18, 2006 This will work, you where missing the quotes in your first example.[code=php:0]<?php require_once("languages/$data.php"); ?>[/code] Link to comment https://forums.phpfreaks.com/topic/31069-solved-include-files-from-data-lt-include-dataphp-gt/#findComment-143486 Share on other sites More sharing options...
ztealmax Posted December 18, 2006 Author Share Posted December 18, 2006 ahh sweet ;Dthank you verry much you made me happy ;) such a no0b misstake of me "ohh wait i am a no0b" ;)//Martin Link to comment https://forums.phpfreaks.com/topic/31069-solved-include-files-from-data-lt-include-dataphp-gt/#findComment-143489 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.