fork download
  1. <?php
  2. $string = "1,1,1;2,5;3,4";
  3. $tests = array("1,2,3;7,1,3;1", "1", "1;1;3;5;7;10;999", "1,1,1;2,5;3,4",
  4. "1,2,11", "9,99", "1,3,1");
  5. foreach ($tests as $test) {
  6. echo "$test: ";
  7. if (!preg_match('/\b(\d+),[^;]*\b\1\b/', $test)) {
  8. print_r(preg_split('/[,;]/', $test));
  9. } else {
  10. echo "No match\n";
  11. }
  12. }
Success #stdin #stdout 0.02s 20520KB
stdin
Standard input is empty
stdout
1,2,3;7,1,3;1: Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 7
    [4] => 1
    [5] => 3
    [6] => 1
)
1: Array
(
    [0] => 1
)
1;1;3;5;7;10;999: Array
(
    [0] => 1
    [1] => 1
    [2] => 3
    [3] => 5
    [4] => 7
    [5] => 10
    [6] => 999
)
1,1,1;2,5;3,4: No match
1,2,11: Array
(
    [0] => 1
    [1] => 2
    [2] => 11
)
9,99: Array
(
    [0] => 9
    [1] => 99
)
1,3,1: No match