3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{ "1": [ { "row": "My name is Trevor\n" }, { "row": "Can you see me?\n" }, { "row": "\f" } ], "2": [ { "row": "Hey there! Some other text.\n" }, { "row": "What is up Trevor?\n" }, { "row": "\f" } ], "3": [ { "row": "Some text on the third column. First row." }, { "row": "\f" } ] }'; $content = json_decode($json, true); class regexTextReplace { private $pattern; private $replacement; public function __construct(array $arguments) { $this->pattern = $arguments['pattern']; $this->replacement = $arguments['replacement']; } public function apply(array $table, $column = false): array { $out = array(); foreach ($table as $col => $rows) { if ($column === false || $col == $column) { $out[$col] = array_map('self::regex_replace', $rows); } else { $out[$col] = $rows; } } return $out; } public function regex_replace(array $table) { return preg_replace($this->pattern, $this->replacement, $table); } } $options = [ 'pattern' => '/Trevor/i', 'replacement' => 'Oliver', ]; $engine = new regexTextReplace($options); $columns = $engine->apply($content, 1); print_r($columns); $options = [ 'pattern' => '/Some/i', 'replacement' => 'A lot of', ]; $engine = new regexTextReplace($options); $columns = $engine->apply($content); print_r($columns);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Use of "self" in callables is deprecated in /in/P7NCu on line 53 Array ( [1] => Array ( [0] => Array ( [row] => My name is Oliver ) [1] => Array ( [row] => Can you see me? ) [2] => Array ( [row] => ) ) [2] => Array ( [0] => Array ( [row] => Hey there! Some other text. ) [1] => Array ( [row] => What is up Trevor? ) [2] => Array ( [row] => ) ) [3] => Array ( [0] => Array ( [row] => Some text on the third column. First row. ) [1] => Array ( [row] => ) ) ) Deprecated: Use of "self" in callables is deprecated in /in/P7NCu on line 53 Deprecated: Use of "self" in callables is deprecated in /in/P7NCu on line 53 Deprecated: Use of "self" in callables is deprecated in /in/P7NCu on line 53 Array ( [1] => Array ( [0] => Array ( [row] => My name is Trevor ) [1] => Array ( [row] => Can you see me? ) [2] => Array ( [row] => ) ) [2] => Array ( [0] => Array ( [row] => Hey there! A lot of other text. ) [1] => Array ( [row] => What is up Trevor? ) [2] => Array ( [row] => ) ) [3] => Array ( [0] => Array ( [row] => A lot of text on the third column. First row. ) [1] => Array ( [row] => ) ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
64.65 ms | 409 KiB | 8 Q