fork download
  1. <?php
  2. /**
  3.  * для вопроса http://h...content-available-to-author-only...e.ru/questions/354054
  4.  */
  5. $custom = array(
  6. 'custom' => 'name1:::::val1;;;;;name2:::::val2;;;;;name3:::::val3',
  7. );
  8.  
  9.  
  10.  
  11. $cursor = 0;
  12. $isKey = TRUE; // true for Key, false for Value
  13. $pos = 0;
  14. $limit = mb_strlen( $custom['custom']);
  15.  
  16. while( TRUE) {
  17. $pos = mb_strpos( $custom['custom'], ($isKey ? ':::::' : ';;;;;'), $cursor);
  18. if( FALSE == $pos) {
  19. if( $isKey) break;
  20. else if( $cursor < $limit) $pos = $limit;
  21. }
  22.  
  23. $sub = substr( $custom['custom'], $cursor, $pos - $cursor);
  24. if( $isKey) {
  25. $key = $sub;
  26. } else {
  27. $custom[ $key] = $sub;
  28. }
  29.  
  30. $isKey = !$isKey;
  31. $cursor = $pos + 5; // 5 == length of separator
  32. if( $cursor >= $limit) break;
  33. }
  34.  
  35.  
  36.  
  37. print_r( $custom);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Array
(
    [custom] => name1:::::val1;;;;;name2:::::val2;;;;;name3:::::val3
    [name1] => val1
    [name2] => val2
    [name3] => val3
)