split string using multiple delimiters

let’s break apart the incoming string on n (new line) or r (carriage return)

[code language=”php”]$data = preg_split(‘/(n|r)/’, $incoming);[/code]

or break up a string on commas, full stops, semi-colons:

[code language=”php”]
$string = "a string. of words, and more, words; some words, and even more. the end";
$bits = preg_split(‘/[\.,;]/’, $string);

Leave a Reply

Your email address will not be published. Required fields are marked *