Skip to content
Advertisement

How to split a string by multiple delimiters in PHP?

"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!

Advertisement

Answer

<?php

$pattern = '/[;,]/';

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

echo '<pre>', print_r( preg_split( $pattern, $string ), 1 ), '</pre>';
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement