Terrorist Man Terrorist Man - 18 days ago 5x
PHP Question

PHP: separate a string based on `|` delimiters

I am trying to figure out a way using PHP that I can parse a string of data from a URL to separate each entry based on the character

. Example data:||||||

Anyone got any ideas?


You can use the explode() function to split the string and remove empty elements with array_filter()

$string = '||||||';
$ips = array_filter(explode('|', $string));

which results in an array containing all your ip adresses

    [0] =>
    [1] =>
    [2] =>
    [3] =>
    [4] =>
    [5] =>

There are also two other functions, split() and preg_split() which supports regular expressions too.