[ create a new paste ] login | about

Link: http://codepad.org/wJriQ4M5    [ raw code | output | fork ]

PHP, pasted on Sep 17:
<?php

$string = '"""JOHN"" <31255555656>","DAHDI/1-1",3948723,,"",';

define('STATE_END',    0);
define('STATE_BEFORE', 1);
define('STATE_INSIDE', 2);

$offset = 0;
$state  = STATE_BEFORE;

while ($state)
{
    switch ($state)
    {
        case STATE_INSIDE;

          $p = strpos($string, '",', $offset);

          if ($p !== false) 
          {
              echo substr($string, $offset, $p - $offset), "\n";

              $offset = $p + 2;
              $state  = STATE_BEFORE;              
          }
          else 
          {
              $state = STATE_END;
          }

          break;

        case STATE_BEFORE:

          $p = strpos($string, '"', $offset);

          if ($p !== false) 
          {
              $offset = $p + 1;
              $state = STATE_INSIDE;
          }
          else 
          {
              $state = STATE_END;
          }

          break;

        default:

          $state = STATE_END;
    }
}


Output:
1
2
3
""JOHN"" <31255555656>
DAHDI/1-1



Create a new paste based on this one


Comments: