Welcome Guest, Not a member yet? Register   Sign In
Addition to core/Lang.php
#1

[eluser]Unknown[/eluser]
I was working on a project with CodeIgniter. And I needed a function to get the array of lines from language file with some prefix or array of lines from by giving an array of keys. But there was no such function, so I wrote such function. And I decided to post it here. May be somebody else need it Smile

So here is the code:

Code:
/**
* Fetch an array of lines from the language array
*
* @access public
* @param mixed    $lines    an array of keys or a string containing a prefix of keys you want
* @return array (if $lines is prefix it will be removed from keys returned)
*/
function lines($lines ='')
{
  $data; // array to be returned
        
  if($lines == ''){ // if there is no parameter return all the values
    $data = $this->language;
        
  }elseif(!is_array($lines)){ // if it is not array then assume it as prefix
    $length = strlen($lines);
    foreach($this->language as $key => $val){
      if(substr($key, 0, $length) == $lines)
      $data[substr($key, $length)] =  $val;
    }
        
  } else { // if it is an array return only values with given index
    foreach($lines as $val){
      $data[] =  $this->language[$val];
    }
  }
        
  return $data;
}




Theme © iAndrew 2016 - Forum software by © MyBB