Terrorist Man Terrorist Man - 1 year ago 140
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download