テキストと定数を含むファイルがあります。定数名と定数値を取得するにはどうすればよいですか。問題は、定数値に時々スペースがあることです。私はファイルを読んでfile()
からforeach
...
例:
define('LNG_UTF-8', 'Universal Alphabet (UTF-8)');
define('LNG_ISO-8859-1', 'Western Alphabet (ISO-8859-1)');
define('LNG_CustomFieldsName', 'Custom Field');
define('LNG_CustomFieldsType', 'Type');
私はすでに試しました:
定数名を取得するには:
$getConstant1 = strpos($mainFileArray[$i], '(\'');
$getConstant2 = strpos($mainFileArray[$i], '\',');
$const = substr($mainFileArray[$i], $getConstant1 + 2, $getConstant2 - $getConstant1 - 2);
定数値を取得するには
$position1 = strpos($file[$i], '\',');
$position2 = strpos($file[$i], '\');');
$rest = substr($file[$i], $position1 + 3, $position2 - $position1 - 2);
ただし、スペースまたは'、'..の場合は機能しません。
これを常に機能させるにはどうすればよいですか?