我从.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 :(得分: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;
}
}