【发布时间】:2017-01-08 16:10:04
【问题描述】:
我可以用普通的字符串函数做到这一点,但如果我想知道这件事是否可以用 regex 方式完成。
$list = array("animal","human","bird");
$input1 = "Hello, I am an /animal/1451/ and /bird/4455";
$input2 = "Hello, I am an /human/4461451";
$input3 = "Hello, I am an /alien/4461451";
$output1 = ["type"=>"animal","number"=>1451],["type"=>"bird","number"=>4455]];
$output2 = [["type"=>"human","number"=>4461451]];
$output3 = [[]];
function doStuff($input,$list){
$input = explode(" ",$input);
foreach($input as $in){
foreach($list as $l){
if(strpos($in,"/".$l) === 0){
//do substr to get number and store in array
}
}
}
}
【问题讨论】:
-
Write codes for me问题?或者你已经尝试过? -
即时更新等待我尝试了什么
-
我被标签弄糊涂了,它应该是php吗? javascript?
-
已更新,但我使用了很多循环
-
js 和 php any 都可以工作
标签: javascript php arrays regex string