Fernand Royale Fernand Royale - 1 year ago 83
PHP Question

Preg_match_all split multiple occurrences

I have a string like this:


-Just one example is not just that.

I did this regular expression

preg_match_all("/[0-9][0-9](?:\|)(?:https\:\/\/)(.*?)/", string, string2);

But it only takes

I wonder how do I get it and only stop when you find the next occurrence of the regular expression and separate it into different arrays

Answer Source

Try this:

preg_match_all("/(?:[0-9][0-9](?:\|)(?:https\:\/\/)(.*?)(?=[\d][\d]\||$))|([\d][\d]\|.*)/", $string, $matches);

Results array in $matches:

[0] => 59|https://site59.com
[1] => 20|https://site20.com
[2] => 30|https://site30.com
[3] => 16|https://site15.com
[4] => 66|https://site66.com
[5] => 29|https://site29.com
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download