fork download
  1. <?php
  2.  
  3. $linhas = "
  4. city=A(100,80);
  5. city=B(160,70);
  6. city=C(110,50);
  7. city=D(140,120);
  8. city=F(155,40);
  9. city=G(210,60);
  10. city=H(190,10);
  11. city=I(170,110);
  12. route=A-C;140;
  13. route=A-D;155;
  14. route=C-F;125;
  15. route=D-B;115;
  16. route=D-I;152;
  17. route=B-F;119;
  18. route=B-G;136;
  19. route=G-F;133;
  20. route=F-H;163;
  21. route=I-H;197;";
  22.  
  23. preg_match_all("~(?:city|route)=(\w+)(?:\(|\-)(\w+)(?:\,|\;)(\w+)~", $linhas, $pontos);
  24.  
  25. echo "<pre>";
  26. print_r($pontos);
  27.  
  28.  
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
<pre>Array
(
    [0] => Array
        (
            [0] => city=A(100,80
            [1] => city=B(160,70
            [2] => city=C(110,50
            [3] => city=D(140,120
            [4] => city=F(155,40
            [5] => city=G(210,60
            [6] => city=H(190,10
            [7] => city=I(170,110
            [8] => route=A-C;140
            [9] => route=A-D;155
            [10] => route=C-F;125
            [11] => route=D-B;115
            [12] => route=D-I;152
            [13] => route=B-F;119
            [14] => route=B-G;136
            [15] => route=G-F;133
            [16] => route=F-H;163
            [17] => route=I-H;197
        )

    [1] => Array
        (
            [0] => A
            [1] => B
            [2] => C
            [3] => D
            [4] => F
            [5] => G
            [6] => H
            [7] => I
            [8] => A
            [9] => A
            [10] => C
            [11] => D
            [12] => D
            [13] => B
            [14] => B
            [15] => G
            [16] => F
            [17] => I
        )

    [2] => Array
        (
            [0] => 100
            [1] => 160
            [2] => 110
            [3] => 140
            [4] => 155
            [5] => 210
            [6] => 190
            [7] => 170
            [8] => C
            [9] => D
            [10] => F
            [11] => B
            [12] => I
            [13] => F
            [14] => G
            [15] => F
            [16] => H
            [17] => H
        )

    [3] => Array
        (
            [0] => 80
            [1] => 70
            [2] => 50
            [3] => 120
            [4] => 40
            [5] => 60
            [6] => 10
            [7] => 110
            [8] => 140
            [9] => 155
            [10] => 125
            [11] => 115
            [12] => 152
            [13] => 119
            [14] => 136
            [15] => 133
            [16] => 163
            [17] => 197
        )

)