简体   繁体   中英

PHP preg_split to nice array

I need some help with preg_split and my code.

I have output:

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

And i need array like:

Array {
 [0] => Test 
 [1] => Test2 
 [2] => Test.adada
 [3] => test_Test
 [4] => test test
 [5] => test-test
}

I dont know how make array like i am write with my output..

Thanks!

use preg_match_all in php

<?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]);    
?>

output will be

Array {
 [0] => Test 
 [1] => Test2 
 [2] => Test.adada
 [3] => test_Test
 [4] => test test
 [5] => test-test
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM