phpregexstringsplit

How to split a string by any of multiple delimiters?


"something here ; and there, oh,that's all!"

I want to split it by ; and ,

so after processing should get:

something here

and there

oh

that's all!

Solution

  • <?php
    
    $pattern = '/[;,]/';
    
    $string = "something here ; and there, oh,that's all!";
    
    echo '<pre>', print_r( preg_split( $pattern, $string ), 1 ), '</pre>';