首頁  >  文章  >  後端開發  >  怎样根据$hello数据将$str层层展开?解决方案

怎样根据$hello数据将$str层层展开?解决方案

WBOY
WBOY原創
2016-06-13 10:16:47763瀏覽

怎样根据$hello数据将$str层层展开?
怎样根据$hello数据将$str层层展开?

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?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/"     );?>



------解决方案--------------------
PHP code
$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;//testprint_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')/**/<div class="clear">
                 
              
              
        
            </div>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn