...

View Full Version : Seems simple file( ); array problems



jbrown1028
07-28-2008, 10:48 PM
For some reason I am having an issue rapping my head around this small problem. It is about as simple as you can get... Let me explain:

I have all of my language files on my server so when my translators translate to their own language my program will pick it up and put the text in the proper places. I will use the English:

Here are the first 6 lines of the english.php file:


$txt['license'] = 'License';
$txt['title'] = 'My Cool Program'
$txt['tool_version'] = $version
$txt['error_message_click'] = 'Click here';
$txt['error_message_try_again'] = 'to try this step again.';
$txt['error_message_bad_try_again'] = 'to try installing anyway, but note that this is <i>strongly</i> discouraged.';
As you can see it is basically an array, I want to leave it in this format $txt['WORD'] so it will be easier to move from one language to another. Now when I had all of the $txt lines in a function like this:

function load_language() {
$txt['license'] = 'License';
$txt['title'] = 'YOOLoader'
$txt['tool_version'] = $version
$txt['error_message_click'] = 'Click here';
$txt['error_message_try_again'] = 'to try this step again.';
$txt['error_message_bad_try_again'] = 'to try installing anyway, but note that this is <i>strongly</i> discouraged.';
}

It works great, although I am now starting the translation section of the program so it will need to call which ever file they choose from the drop down box:
English = english.php
French = french.php
...and so on

So my brain get stuck on using an include, but with php5 you can not have a remote include file. So this leads me to use the file(http://www.jbrowns.com/yoo/english.php) here is the code that I am trying to use:



function load_language_data(){
global $txt;
if ($language == "") {
$language = "english";
}
$txt = file("http://www.jbrowns.com/yoo/" . $language .".php");
foreach ($txt as $line_num => $line) {
//echo $line . "<br />\n";
}
}
That is not allowing the array to function properly because it is placing everything in $txt[0] = "txt['license'] = 'License'"

Can somebody slap me upside the head and tell me what I am forgetting?

Thanks,
Jeff

scoop_987
07-28-2008, 11:07 PM
Why cant you include the file? Just ask the owner for a copy, thats if you not the owner.

This is what php.net states about file:

file — Reads entire file into an array

So it READS the file into an array. So its basically reading the file and not splitting it, for PHP to parse it and get all the variables, you have to include (or require it). Otherwise you wont get them

CFMaBiSmAd
07-28-2008, 11:07 PM
When you use a URL in a php function to include, read, or otherwise get a remote file that ends in .php, that file will be parsed as php code at the remote location (assuming php is installed) and you will only receive any content that is output by that file.

Is there a reason you are doing this remotely as that would slow every page load by the additional time necessary to make the request to the remote server and wait for it to server up the file?

jbrown1028
07-28-2008, 11:15 PM
Yes, this is an installer for templates for Joomla basically they will add 1 file to their Joomla directory. The installer is only 1 file in size, the CSS is called from my server under the yoo directory and the language files are updated using my site and will build the php (or whatever I specify them as) files once completed.

This file will only be ran once by the site administrator, and only the administrator will have access to this file. This will not be a live program for multiple people to run.

I am trying to make this program as simple as possible for the end users to install templates and load the sample data that I am creating for a Joomla install. As for the server,

@scoop_987 (http://www.codingforums.com/member.php?u=64673) yes it is my server but my clients will be installing the yooloader.php on their server, so yes I will give them permission to use the language files on their server for 1 time use.

Still I do remember a way that I pulled text from a file and made the key be assigned, I just can't remember how I did that.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum