1

我从我的 .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"
    );
4

1 回答 1

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;           
            }
        }
于 2012-10-16T08:06:16.307 回答