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 7 of 7

Thread: php arrays

  1. #1
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts

    php arrays

    Hi Guys,
    Anybody know how to achieve this http://www.codingforums.com/showthread.php?t=243599 using php arrays?
    Thanks

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    PHP Code:
    $phrase = array();
    $phrase[1] = "about";
    $phrase[2] = "contact";
    $phrase[3] = "services";
    $phrase[4] = "hmmm";
    $phrase[5] = "francais";
    $phrase[6] = "car";
    $phrase[7] = "deutsch";
    $phrase[8] = "dsad";

    $phrase_length count($phrase);
    for (
    $i 1$i $phrase_length$i++)
    {
        echo 
    '{exp:lg_ml:translate key="' $phrase[$i] + '"}';


  • #3
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts
    Thanks but when I ran the code the output was 7 zeros - "0000000"

    Code:
    <?php
    $phrase = array();
    $phrase[1] = "about";
    $phrase[2] = "contact";
    $phrase[3] = "services";
    $phrase[4] = "hmmm";
    $phrase[5] = "francais";
    $phrase[6] = "car";
    $phrase[7] = "deutsch";
    $phrase[8] = "dsad";
    
    $phrase_length = count($phrase);
    for ($i = 1; $i < $phrase_length; $i++)
    {
        echo '{exp:lg_ml:translate key="' + $phrase[$i] + '"}';
    }  
    
    
    ?>
    my intended output is:

    {exp:lg_ml:translate key="about"}
    {exp:lg_ml:translate key="contact"}
    {exp:lg_ml:translate key="services"}
    ..and so on
    Last edited by howie2009; 11-13-2011 at 01:07 PM.

  • #4
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts
    ok my hack seems to work

    Code:
    <?php
    $phrase=array();
    $phrase[1] = "about";
    $phrase[2] = "contact";
    $phrase[3] = "services";
    $phrase[4] = "hmmm";
    $phrase[5] = "francais";
    $phrase[6] = "car";
    $phrase[7] = "deutsch";
    $phrase[8] = "dsad";
    
    
    $phrase_length = count($phrase);
    for ($i = 1; $i <= $phrase_length; $i++)
      {
      echo "{exp:lg_ml:translate key=\"" .$phrase[$i] . "\"}<br />";
    
      }
    ?>
    Thanks for the pointer.

  • #5
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts
    last gasp attempt.
    The above code works in a standalone php file so thanks for that!
    What I actually need is for the tag (eg {exp:lg_ml:translate key="about"}) not to be echoed on screen but to be generated in the code such that when the template renders it sees the tag generated eg {exp:lg_ml:translate key="about"} and applies the translation. I am using a cms so these tags have predefined values.
    The tag {exp:lg_ml:translate key="about"} actually holds eg the German translation of the word about so it outputs just "uber" on screen.

    So apart from echo or vprintf is there another word that just applies the array so its available in the code for the browser to render?

    I effectively need
    {exp:lg_ml:translate key="about"}
    {exp:lg_ml:translate key="services"}
    {exp:lg_ml:translate key="whatever"}
    ...
    generated in the code via the array and then for the resultant code to be rendered.

    Is there a way even to make the php array render before everything else. CAn precedence of some sort be applied. Sorry newbie to php

    THANKS!
    Last edited by howie2009; 11-13-2011 at 03:06 PM.

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Whoops, I didn't use the proper concatenation operator.
    Quote Originally Posted by howie2009 View Post
    So apart from echo or vprintf is there another word that just applies the array so its available in the code for the browser to render?

    I effectively need
    {exp:lg_ml:translate key="about"}
    {exp:lg_ml:translate key="services"}
    {exp:lg_ml:translate key="whatever"}
    ...
    generated in the code via the array and then for the resultant code to be rendered.
    What template engine are you using? The PHP code is executed in the order it is loaded, so presumably you just need to insert it in to your template after it's loaded, but before it's parsed. You'll have to provide some more information about how you are loading and parsing the templates though, if you want people to be able to help you with more detail.

  • #7
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts
    Ok here goes my novice attempt of explaining things.
    I use the cms expressionengine 1.7.0 and {exp:lg_ml:translate key="about"} is a tag that relates to a translation module installed in the cms control panel - in this case the tag equates to the value "uber". When I render the array above nothing outputs (yet in a standalone php file it renders fine) so it appears to be a cms environment issue. The tag is effectively a global variable I expect(strangely other global variables i tested in the array do output their values correctly). Anyway this tag in question outputs blank with no value so perhaps the the tag is the last thing to execute in the template hence its blank in the array output? Idea is the array outputs eg {exp:lg_ml:translate key="about"} and the translation php snippet in the module comes along sees the tag {exp:lg_ml:translate key="about"} and changes it to "uber" (which is retrieved from an xml file) and output uber on screen.

    eg if I used {site_url} in the array instead of generating the tag {exp:lg_ml:translate key="about"} I would get eg "www.mydomain.com about" outputted as www.mydomain.com is the value associated with {site_url}

    i.e: echo "{site_url} .$phrase[$i]<br />";


    ...maybe something along the lines of:

    for ($i = 1; $i <= $phrase_length; $i++)
    {
    $resPhrase = "{exp:lg_ml:translate key=\"" .$phrase[$i] . "\"}<br />";
    echo "$resPhrase"

    }

    ..may work if u could suggest the correct syntax please?

    Apologies if I aint explaining it well.
    THANKS

    This the specific code i use in the cms

    Code:
    <?php
    $phrase=array();
    {exp:structure_entries}   => see http://buildwithstructure.com/documentation/structure_entries/
    $phrase[{count}] = "{title}";
    {/exp:structure_entries}
    $phrase_length = count($phrase);
    for ($i = 1; $i <= $phrase_length; $i++)
      {
    
     echo "{exp:lg_ml:translate key=\"" .$phrase[$i] . "\"}<br />";   => see http://ee-garage.com/uploads/addons/ee1/docs/lg-multi-language.1.1.0.commercial.pdf
      }
    ?>
    which equates effectively to the array code above in the examples
    Last edited by howie2009; 11-14-2011 at 03:20 AM.


  •  

    Posting Permissions

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