日期:2014-05-17 浏览次数:20659 次
<?php $my_arr=array(); $str="DIR_FS_AAA . DIR_WS_CLASSES"; $hello=array( "DIR_FS_AAA" =>"DIR_WS_TEMPLATE.'includes/'", "DIR_WS_CLASSES" =>"DIR_WS_ADMIN.'helloworld'", "DIR_WS_TEMPLATE" =>"template/", "DIR_WS_ADMIN" =>"admin/" ); //怎样得到这样的结果数组: $my_arr=array( "DIR_FS_AAA . DIR_WS_CLASSES", "DIR_WS_TEMPLATE.'includes/'.DIR_WS_TEMPLATE.'includes/'", "template/includes/admin/includes/" ); ?>
$my_arr[] = $str; $tmp = preg_replace("/[A-Z_]+/e", "\$hello['\\0']", $str); $my_arr[] = $tmp; $tmp = preg_replace("/[\"']?\s*\.?\s*([A-Z_]+)\s*\.?\s*[\"']/e", "\$hello['\\1']", $tmp); $my_arr[] = $tmp; //test print_r($my_arr); /** Array ( [0] => DIR_FS_AAA . DIR_WS_CLASSES [1] => DIR_WS_TEMPLATE.'includes/' . DIR_WS_ADMIN.'helloworld' [2] => template/includes/admin/helloworld' ) /**/