【发布时间】:2012-06-25 07:06:11
【问题描述】:
我有带有文本和常量的文件。如何获取常量名称和常量值。问题是常量值有一些时间空间。我使用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);
但在空格或','时不起作用...
我怎样才能让它一直工作??
【问题讨论】:
-
为什么不能简单地
include文件并将常量用作常量?
标签: php