[ create a new paste ] login | about

Link: http://codepad.org/Sh6fZGNf    [ raw code | output | fork ]

aceballos - PHP, pasted on Apr 22:
<?php

# -------------------------------------------- [ dataxchg.php (fragment)
   
      function param2Hidden ($hash_this)
         {
         $str_result = '';	
         foreach ($hash_this as $str_thisname => $str_thisvalue) {
	   if (is_array($str_thisvalue)) {
	      foreach ($str_thisvalue as $str_thiselement)
	         { $str_result .= "\t<input type=\"hidden\" \"name=\"$str_thisname\[\]\" value=\"$str_thiselement\" /> \n"; }
	      }
	   else
	      { $str_result .= "\t<input type=\"hidden\" \"name=\"$str_thisname\" value=\"$str_thisvalue\" /> \n"; }
	   }
         return $str_result;	
         }   
            
      function ah2List ($ah_this, $str_id='', $str_name='data', $str_class='')
         {
         $str_result = '';	
         $str_result .= "<ol ";
         if ($str_id) $str_result .= 'id="'.$str_id.'" ';
         $str_result .= 'name="'.$str_name.'" ';
         if ($str_class) $str_result .= 'class="'.$str_class.'" ';
         $str_result .= "> \n";
         foreach ($ah_this as $hash_this) {
      	   $str_thisclass = ($hash_this["class"]) ? 'class="'.$hash_this["class"].'"' : '';  
      	   $str_thislink = ($hash_this["link"]) ? $hash_this["link"] : '';
      	   $str_thisname = $hash_this["name"]; 
      	   $str_thisicon = ($hash_this["icon"]) ? $hash_this["icon"] : ''; 
   	   $str_result .= "\t<li $str_thisclass>";
   	   if ($str_thislink) $str_result .= "<a href=\"$str_thislink\">";
   	   if ($str_thisicon) $str_result .= "<img src=\"$str_thisicon\" class=\"icon\" alt=\"$str_thisname\" />";
   	   $str_result .= $str_thisname;
   	   if ($str_thislink) $str_result .= "</a>";
   	   $str_result .= "</li> \n";
            }
         $str_result .= "</ol> \n";	
         return $str_result;	
         }


# -------------------------------------------- [ auxiliary
   
      
   $hash_imidazopyridine = array("q1"=>"Alpidem", "q2"=>"Saripidem", "q3"=>"Zolpidem"); 
    
   $ah_subd = array(
      array ("link"=>'chon.php', "name"=>'Chondrostei'),
      array ("class"=>'teleostei', "link"=>'neopt.php', "name"=>'Neopterygii'),
      array ("class"=>'lungfish', id=>'', "link"=>'coel.php', "name"=>'Coelacanths'),
      array ("class"=>'amniota', "name"=>'Tetrapods'),
      ); 
   
   print param2Hidden($hash_imidazopyridine)."\n\n";
   
   print ah2List($ah_subd, 'fish', 'Osteichthyes', 'testdata')."\n\n";
   

?> 


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
	<input type="hidden" "name="q1" value="Alpidem" /> 
	<input type="hidden" "name="q2" value="Saripidem" /> 
	<input type="hidden" "name="q3" value="Zolpidem" /> 


<ol id="fish" name="Osteichthyes" class="testdata" > 
	<li ><a href="chon.php">Chondrostei</a></li> 
	<li class="teleostei"><a href="neopt.php">Neopterygii</a></li> 
	<li class="lungfish"><a href="coel.php">Coelacanths</a></li> 
	<li class="amniota">Tetrapods</li> 
</ol> 


 


Create a new paste based on this one


Comments: