Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2006
    Location
    Fostoria, Ohio
    Posts
    35
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Seems simple file( ); array problems

    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:

    Code:
    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

  • #2
    New Coder
    Join Date
    Jul 2008
    Posts
    91
    Thanks
    4
    Thanked 9 Times in 9 Posts
    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
    Current Project: Nothing at the minute

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    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?
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    New Coder
    Join Date
    Sep 2006
    Location
    Fostoria, Ohio
    Posts
    35
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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 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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •