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 に答える