0

我的php问题如下:

我有这个字符串:$days="Monday* Tuesday* Wednesday*"

我想创建一个这样的数组:$d[1]="Monday"; $d[2]="Tuesday"; $d[3]="Wednesday"

我感觉到解决方案通过了,explode(*, $days)但我无法更进一步

感谢您的帮助 :)

4

5 回答 5

1
$days="Monday* Tuesday* Wednesday*";
$d=explode('* ', $days);

或者

$days="Monday* Tuesday* Wednesday*";
$d=explode(' ', str_replace('*','',$days));

用于排除最后一个单词末尾的“*”。

于 2013-08-05T22:18:03.720 回答
1
explode('* ', trim($days, '*'));
于 2013-08-05T22:18:45.837 回答
1

你应该使用:

explode("* ", $days)

但是国际海事组织,我会使用这样的昏迷:

$days  = "Monday,Tuesday,Wednesday";
$days = explode(",", $days);
echo $days[0]; // => Monday
echo $days[1]; // => Tuesday
于 2013-08-05T22:19:16.813 回答
0
$days="Monday* Tuesday* Wednesday*";
$exploded = explode('* ',substr($days, 0, -1));
print_r($exploded);

输出:

Array
(
    [0] => Monday
    [1] => Tuesday
    [2] => Wednesday
)
于 2013-08-05T22:18:46.503 回答
0
<?php
$days = 'Monday* Tuesday* Wednesday*';
$d = array_filter(explode('* ', $days));
于 2013-08-05T22:59:49.020 回答