3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $str = "0/1/2/3/4/5/6/7/8/9/a/b/c/d/e/f 0/1/2/3/4/5/6/7/8/9/a/b/c/d/e/f"; $lines = array($str); $results = array(); while ($line = array_shift($lines)) { if (preg_match("/(\w+)(?:\/\w+)+/ui", $line, $match, PREG_OFFSET_CAPTURE)) { list($string, $offset) = $match[1]; array_push($lines, sprintf("%s%s", substr($line, 0, $offset + strlen($string)), substr($line, $offset + strlen($match[0][0])) )); array_push($lines, sprintf("%s%s", substr($line, 0, $offset), substr($line, $offset + strlen($string) + 1) )); } else { $results[] = $line; } } print_r($results);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => 0 0 [1] => 0 1 [2] => 1 0 [3] => 0 2 [4] => 1 1 [5] => 2 0 [6] => 0 3 [7] => 1 2 [8] => 2 1 [9] => 3 0 [10] => 0 4 [11] => 1 3 [12] => 2 2 [13] => 3 1 [14] => 4 0 [15] => 0 5 [16] => 1 4 [17] => 2 3 [18] => 3 2 [19] => 4 1 [20] => 5 0 [21] => 0 6 [22] => 1 5 [23] => 2 4 [24] => 3 3 [25] => 4 2 [26] => 5 1 [27] => 6 0 [28] => 0 7 [29] => 1 6 [30] => 2 5 [31] => 3 4 [32] => 4 3 [33] => 5 2 [34] => 6 1 [35] => 7 0 [36] => 0 8 [37] => 1 7 [38] => 2 6 [39] => 3 5 [40] => 4 4 [41] => 5 3 [42] => 6 2 [43] => 7 1 [44] => 8 0 [45] => 0 9 [46] => 1 8 [47] => 2 7 [48] => 3 6 [49] => 4 5 [50] => 5 4 [51] => 6 3 [52] => 7 2 [53] => 8 1 [54] => 9 0 [55] => 0 a [56] => 1 9 [57] => 2 8 [58] => 3 7 [59] => 4 6 [60] => 5 5 [61] => 6 4 [62] => 7 3 [63] => 8 2 [64] => 9 1 [65] => a 0 [66] => 0 b [67] => 1 a [68] => 2 9 [69] => 3 8 [70] => 4 7 [71] => 5 6 [72] => 6 5 [73] => 7 4 [74] => 8 3 [75] => 9 2 [76] => a 1 [77] => b 0 [78] => 0 c [79] => 1 b [80] => 2 a [81] => 3 9 [82] => 4 8 [83] => 5 7 [84] => 6 6 [85] => 7 5 [86] => 8 4 [87] => 9 3 [88] => a 2 [89] => b 1 [90] => c 0 [91] => 0 d [92] => 1 c [93] => 2 b [94] => 3 a [95] => 4 9 [96] => 5 8 [97] => 6 7 [98] => 7 6 [99] => 8 5 [100] => 9 4 [101] => a 3 [102] => b 2 [103] => c 1 [104] => d 0 [105] => 0 e [106] => 0 f [107] => 1 d [108] => 2 c [109] => 3 b [110] => 4 a [111] => 5 9 [112] => 6 8 [113] => 7 7 [114] => 8 6 [115] => 9 5 [116] => a 4 [117] => b 3 [118] => c 2 [119] => d 1 [120] => e 0 [121] => f 0 [122] => 1 e [123] => 1 f [124] => 2 d [125] => 3 c [126] => 4 b [127] => 5 a [128] => 6 9 [129] => 7 8 [130] => 8 7 [131] => 9 6 [132] => a 5 [133] => b 4 [134] => c 3 [135] => d 2 [136] => e 1 [137] => f 1 [138] => 2 e [139] => 2 f [140] => 3 d [141] => 4 c [142] => 5 b [143] => 6 a [144] => 7 9 [145] => 8 8 [146] => 9 7 [147] => a 6 [148] => b 5 [149] => c 4 [150] => d 3 [151] => e 2 [152] => f 2 [153] => 3 e [154] => 3 f [155] => 4 d [156] => 5 c [157] => 6 b [158] => 7 a [159] => 8 9 [160] => 9 8 [161] => a 7 [162] => b 6 [163] => c 5 [164] => d 4 [165] => e 3 [166] => f 3 [167] => 4 e [168] => 4 f [169] => 5 d [170] => 6 c [171] => 7 b [172] => 8 a [173] => 9 9 [174] => a 8 [175] => b 7 [176] => c 6 [177] => d 5 [178] => e 4 [179] => f 4 [180] => 5 e [181] => 5 f [182] => 6 d [183] => 7 c [184] => 8 b [185] => 9 a [186] => a 9 [187] => b 8 [188] => c 7 [189] => d 6 [190] => e 5 [191] => f 5 [192] => 6 e [193] => 6 f [194] => 7 d [195] => 8 c [196] => 9 b [197] => a a [198] => b 9 [199] => c 8 [200] => d 7 [201] => e 6 [202] => f 6 [203] => 7 e [204] => 7 f [205] => 8 d [206] => 9 c [207] => a b [208] => b a [209] => c 9 [210] => d 8 [211] => e 7 [212] => f 7 [213] => 8 e [214] => 8 f [215] => 9 d [216] => a c [217] => b b [218] => c a [219] => d 9 [220] => e 8 [221] => f 8 [222] => 9 e [223] => 9 f [224] => a d [225] => b c [226] => c b [227] => d a [228] => e 9 [229] => f 9 [230] => a e [231] => a f [232] => b d [233] => c c [234] => d b [235] => e a [236] => f a [237] => b e [238] => b f [239] => c d [240] => d c [241] => e b [242] => f b [243] => c e [244] => c f [245] => d d [246] => e c [247] => f c [248] => d e [249] => d f [250] => e d [251] => f d [252] => e e [253] => e f [254] => f e [255] => f f )