我的PHP的問題是如下內容的數組:PHP - 創建具有爆炸
我有這個字符串:$days="Monday* Tuesday* Wednesday*"
我想創建一個這樣的數組:$d[1]="Monday"; $d[2]="Tuesday"; $d[3]="Wednesday"
我感覺到,溶液流通過explode(*, $days)
但我無法得到進一步
謝謝您的幫助:)
我的PHP的問題是如下內容的數組:PHP - 創建具有爆炸
我有這個字符串:$days="Monday* Tuesday* Wednesday*"
我想創建一個這樣的數組:$d[1]="Monday"; $d[2]="Tuesday"; $d[3]="Wednesday"
我感覺到,溶液流通過explode(*, $days)
但我無法得到進一步
謝謝您的幫助:)
$days="Monday* Tuesday* Wednesday*";
$d=explode('* ', $days);
或者最後一個字的結束
$days="Monday* Tuesday* Wednesday*";
$d=explode(' ', str_replace('*','',$days));
爲排除 「*」。
explode('* ', trim($days, '*'));
$days="Monday* Tuesday* Wednesday*";
$exploded = explode('* ',substr($days, 0, -1));
print_r($exploded);
輸出:
Array
(
[0] => Monday
[1] => Tuesday
[2] => Wednesday
)
你應該使用:
explode("* ", $days)
但IMO,我會用這樣的昏迷:
$days = "Monday,Tuesday,Wednesday";
$days = explode(",", $days);
echo $days[0]; // => Monday
echo $days[1]; // => Tuesday
<?php
$days = 'Monday* Tuesday* Wednesday*';
$d = array_filter(explode('* ', $days));
如何處理$ days字符串的來源以使此easer – 2013-08-05 22:21:38