0
使用file_get_contents我能得到一個樹枝文件的內容,其中只包含一個多維數組:轉換嫩枝數組PHP數組
嫩枝:
{% set settings = {
theme : '#91141b',
transforms : {
thumb : { mode:'crop', width:300, height:300, quality:80, position:'center-center'},
small : { mode:'fit', width:100, height:100, quality:70, position:'center-center'},
header : { mode:'fit', height:800, quality:80, position:'center-center'},
mobile : { mode:'crop', width:640, height:1136, quality:60, position:'center-center'}
},
globals : {
telephone : '123456678',
address : '42 Wallaby Way, Sydney'
},
social : {
facebook : 'http://www.facebook.com',
twitter : 'http://www.twitter.com',
linkedin : 'http://www.linkedin.com',
youtube : 'http://www.youtube.com'
}
} %}
在PHP中,我現在有這個字符串玩:
{% set settings = { theme : '#91141b', transforms : { thumb : { mode:'crop', width:300, height:300, quality:80, position:'center-center'}, small : { mode:'fit', width:100, height:100, quality:70, position:'center-center'}, header : { mode:'fit', height:800, quality:80, position:'center-center'}, mobile : { mode:'crop', width:640, height:1136, quality:60, position:'center-center'} }, globals : { telephone : '123456678', address : '42 Wallaby Way, Sydney' }, social : { facebook : 'http://www.facebook.com', twitter : 'http://www.twitter.com', linkedin : 'http://www.linkedin.com', youtube : 'http://www.youtube.com' } } %}
有沒有辦法把它變成一個可用的PHP多維數組?就像這樣:
PHP:
$settings = array(
'theme' => '#91141b',
'transforms' => [
'thumb' => [ 'mode'=>'crop', 'width'=>300, 'height'=>300, 'quality'=>80, 'position'=>'center-center'],
'small' => [ 'mode'=>'fit', 'width'=>100, 'height'=>100, 'quality'=>70, 'position'=>'center-center'],
'header' => [ 'mode'=>'fit', 'height'=>800,'quality'=>80, 'position'=>'center-center'],
'mobile' => [ 'mode'=>'crop', 'width'=>640, 'height'=>1136,'quality'=>60, 'position'=>'center-center']
],
'globals' => [
'telephone' => '123456678',
'address' => '42 Wallaby Way, Sydney'
],
'social' => [
'facebook' => 'http://www.facebook.com',
'twitter' => 'http://www.twitter.com',
'linkedin' => 'http://www.linkedin.com',
'youtube' => 'http://www.youtube.com'
]
);
我不知道是否有一個解析器函數,我不知道的。
感謝,
馬克
爲什麼要將樹枝數組提取到PHP中? – DarkBee