PHP preg_split 到漂亮的数组
PHP preg_split to nice array
我在 preg_split 和我的代码方面需要一些帮助。
我有输出:
FGT-603906536077 # == [ Test ] name: Test == [ Test2 ] name: Test2 ==
[ Test.adada ] name: Test.adada == [ test_Test ] name: test_Test == [
test test ] name: test test == [ test-test ] name: test-test
我需要这样的数组:
Array {
[0] => Test
[1] => Test2
[2] => Test.adada
[3] => test_Test
[4] => test test
[5] => test-test
}
我不知道如何像我用我的输出写的那样制作数组..
谢谢!
在php
中使用preg_match_all
<?php
$your_string = "FGT-603906536077 # == [ Test ] name: Test == [ Test2 ] name: Test2 == [ Test.adada ] name: Test.adada == [ test_Test ] name: test_Test == [ test test ] name: test test == [ test-test ] name: test-test";
preg_match_all('/\[(.*?)\]/', $your_string, $out);
echo "<pre>";print_r($out[1]);
?>
输出将是
Array {
[0] => Test
[1] => Test2
[2] => Test.adada
[3] => test_Test
[4] => test test
[5] => test-test
}
我在 preg_split 和我的代码方面需要一些帮助。
我有输出:
FGT-603906536077 # == [ Test ] name: Test == [ Test2 ] name: Test2 == [ Test.adada ] name: Test.adada == [ test_Test ] name: test_Test == [ test test ] name: test test == [ test-test ] name: test-test
我需要这样的数组:
Array {
[0] => Test
[1] => Test2
[2] => Test.adada
[3] => test_Test
[4] => test test
[5] => test-test
}
我不知道如何像我用我的输出写的那样制作数组..
谢谢!
在php
中使用preg_match_all<?php
$your_string = "FGT-603906536077 # == [ Test ] name: Test == [ Test2 ] name: Test2 == [ Test.adada ] name: Test.adada == [ test_Test ] name: test_Test == [ test test ] name: test test == [ test-test ] name: test-test";
preg_match_all('/\[(.*?)\]/', $your_string, $out);
echo "<pre>";print_r($out[1]);
?>
输出将是
Array {
[0] => Test
[1] => Test2
[2] => Test.adada
[3] => test_Test
[4] => test test
[5] => test-test
}