[pmwiki-devel] php arrays

J. Meijer commentgg at hotmail.com
Wed Dec 27 15:36:52 CST 2006



Daniel I have a bit of a problem with your mail. If the title says it all, then I presume you want to generate the verbose code below using arrays and a template. Which would allow you to be more flexible. So I'll responds that first. 

Constructing data from a template is simple in PHP. For example take the german control to be generated. The following are equivalent:

   $links[1] = "<input name='langpair' value='en|de' title='Deutsch/German' 
     src='germany.jpg' height='10' type='image' width='15'>";

    $data=array('en|de', 'Deutsch/German','germany.jpg');
    $links[1] = "<input name='langpair' value=$data[0] title=$data[1] src=$data[2] height='10' type='image' width='15'>";

Now collect all the langpair data into a mutidimensional array:

    $langdata=array(
       array('en|fr', 'Fran&#231;ais/French', 'france.jpg'),
       array('en|de', 'Deutsch/German','germany.jpg'),
       .. # all other entries go here (the final entry doesn't have the trailing comma)
   );

And loop over it filling the template:

   foreach($langdata as $n => $data) # $n holds the numeric index 0..n
      $links[$n] = "<input name='langpair' value=$data[0] title=$data[1] src=$data[2] height='10' type='image' width='15'>";

That should work and be much easier to manage. Hope this answers your question. 

/jm





On 12/26/06,  dso <dso at moosoft.com> wrote:
I have a recipe I am working on but my PHP isn't so good.

  $width = $vars["width"];
  $height = $vars["height"];

  $url   = $ScriptUrl . "/" . $pagename;

  $links[0] = "<input name='langpair' value='en|fr'
title='Fran&#231;ais/French' src='france.jpg' height='10' type='image'
width='15'>";
  $links[1] = "<input name='langpair' value='en|de'
title='Deutsch/German' src='germany.jpg' height='10' type='image'
width='15'>";
  $links[2] = "<input name='langpair' value='en|it'
title='Italiano/Italian' src='italy.jpg' height='10' type='image'
width='15'>";
  $links[3] = "<input name='langpair' value='en|pt'
title='Portugu&#234;s/Portuguese' src='portugal.jpg' height='10'
type='image' width='15'>";
  $links[4] = "<input name='langpair' value='en|es'
title='Espa&#241;ol/Spanish' src='spain.jpg' height='10' type='image'
width='15'>";
  $links[5] = "<input name='langpair' value='en|ja'
title='&#26085;&#26412;&#35486;/Japanese' src='japan.jpg' height='10'
type='image' width='15'>";
  $links[6] = "<input name='langpair' value='en|ko'
title='&#54620;&#44397;&#50612;/Korean' src='korea.jpg' height='10'
type='image' width='15'>";
  $links[7] = "<input name='langpair' value='en|zh-CN'
title='&#20013;&#25991;&#65288;&#31616;&#20307;&#65289;/Chinese
Simplified' src='china.jpg' height='10' type='image' width='15'>";
  $links[8] = "<input name='langpair' value='en|ar'
title='&#1593;&#1585;&#1576;&#1610;/Arabic' src='sa.jpg' height='10'
type='image' width='15'>";

  $r = "\n<form action='http://www.google.com/translate'
target='_blank'>\n";
  $r .= "<input name='u' value='$url' type='hidden' />\n";
  $r .= "<input name='hl' value='en' type='hidden'>\n";
  $r .= "<input name='ie' value='UTF8' type='hidden'>\n";
  $r .= "<table width='100pct' cellpadding='1' cellspacing='0'>\n";

  //loop to create table here

  $r .= "</table>\n";
  $r .= "</form>\n";


How do you create a loop such that the array of links can be output in
an arbitrary fashion based on the width and height given?  Thanks!

Daniel


_________________________________________________________________
Fixing up the home? Live Search can help.
http://imagine-windowslive.com/search/kits/default.aspx?kit=improve&locale=en-US&source=wlmemailtaglinenov06


More information about the pmwiki-devel mailing list