Jump to content

[SOLVED] include files, from $data <? include $data.php ?> ??


ztealmax

Recommended Posts

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  ;) ***
[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
it just doesnt include file
i 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
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 @data
something 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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.