Jump to content

More stuff about include and defined data


ztealmax

Recommended Posts

hi im trying to include a language file with some scripts for example like this:


this is my [b]index.php[/b]
[code]<?php include("language.php?language=config/language.cfg"); ?>

<? echo lan_0; ?>[/code]

this is my [b]language.php[/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>
<?php require_once("languages/$data.php"); ?>
</pre>[/code]

and this is my [b]language.cfg[/b]
[code]svenska[/code]

and finally the language file
[code]<?php
// Language Svenska
define("lan_0", "Svenska");
// Mainmenu
define("lan_1", "Huvudmeny");
define("lan_2", "Nyheter");
define("lan_3", "länkar");
define("lan_4", "forum");
define("lan_5", "Nedladdningar");
define("lan_6", "Medlemmar");
?>[/code]

so i want to be able to access the defined values for example
[b]lan_0[/b] thats says what langueage it is. but i must be doing a fatal mistace couse all i get is
echoed out:

lan_0 ([i]here it should say[/i] [b]svenska[/b])

So if you know how to solve this, or know what i did wrong please post it ;)
Thanx
//Martin
Are you sure this makes sense:

[code=php:0]include("language.php?language=config/language.cfg");[/code]


If you want to pass a variable to an included file, just set it like this:

[code=php:0]$language = 'config/language.cfg';
include('language.php');[/code]


$language will be available inside the included file.

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.