Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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! 
like image 806
omg Avatar asked Sep 21 '09 03:09

omg


People also ask

How to split string with multiple delimiters in PHP?

You can get the values into an array using Devin's or Meder's method. echo implode("\n", $resultingArray); Or use <br /> if it's HTML you want.

What is delimiter PHP?

Delimiters ¶ A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character. Leading whitespace before a valid delimiter is silently ignored. Often used delimiters are forward slashes ( / ), hash signs ( # ) and tildes ( ~ ). The following are all examples of valid delimited patterns.


1 Answers

<?php  $pattern = '/[;,]/';  $string = "something here ; and there, oh,that's all!";  echo '<pre>', print_r( preg_split( $pattern, $string ), 1 ), '</pre>'; 
like image 111
meder omuraliev Avatar answered Sep 28 '22 14:09

meder omuraliev