2012-10-13 63 views
0

我從我的PHP文件獲取內容,並希望在一個數組推獲取的結果是一樣的東西:解析內容,並推入陣列

//english error 

$lang['error_incorrect_login'] = "The username or password doesn't match. Please try again"; 

$lang['error_user_exist'] = "The Username already exist in database. Please try using a different Username"; 

$lang['error_email_exist'] = "Email address already exist in database"; 

這是我的PHP文件的實際內容

,我需要的結果數組,如:

array(
    ['error_incorrect_login'] = "The username or password doesn't match. Please try again", 
    ['error_user_exist'] = "The Username already exist in database. Please try using a different Username", 
    ['error_email_exist'] = "Email address already exist in database" 
); 

其實我是想解析

$lang['error_incorrect_login'] = The username or password doesn't match. Please try again"; 

語句類型&推入一個數組。

array(
     ['error_incorrect_login'] = "The username or password doesn't match. Please try again", 
     ['error_user_exist'] = "The Username already exist in database. Please try using a different Username", 
     ['error_email_exist'] = "Email address already exist in database" 
    ); 
+0

$ LANG * *是你想要的形式,給人的print_r正是這個。 – davidkonrad

+0

以及它在我的.php文件中作爲內容。我正在使用$ contents = file($ my_php_file);並且如果使用foreach($ contents as $ b => $ v)debug($ v); \t}以上結果出現 –

+0

當然你剛好在'include(file.php);的foreach($ LANG ...' – SmokeyPHP

回答

0

感謝我的朋友用explode'='這樣的:

$lang = '$lang'; 

$content = array(); 
     while (!feof($fp)) { 
      $line = trim(fgets($fp)); 
      if (($line != "<?php if (!defined('BASEPATH')) exit('No direct script access allowed');") && ($line != "")) { 

       $explode = explode("=", $line); 
       $content['log'][] = str_replace("']", "", str_replace($lang . "['", "", trim($explode[0]))); 

       if (!isset($explode[1])) 
        $msg = ""; 
       else 
        $msg = str_replace(";", "", str_replace("'", "", trim($explode[1]))); 

       $content['msg'][] = $msg;   
      } 
     }