3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function matchStrings($str) { $ret = array(); // $ret = explode("\n", $str); foreach($ret as $asub) { $asub = str_replace('x', '', $asub); preg_match('/^(sh[0-9]+sh)+/', trim($asub), $ret['matches'][]); } $ret = array_unique($ret['matches']); foreach($ret as $sfind) { var_dump($sfind); } return $ret; // } $test = <<<MULTI xx xx sh1sh xx xx xx sh2sh xx xx xx xx sh**sh xx xx x xx xx sh3xxxsh xx xx sh4shsh5sh xxx MULTI; $matches = matchStrings($test); print_r($matches);
based on oGYSB
Output for 7.2.0
Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 array(2) { [0]=> string(5) "sh1sh" [1]=> string(5) "sh1sh" } Array ( [0] => Array ( [0] => sh1sh [1] => sh1sh ) )
Output for 7.0.0 - 7.1.10
Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 array(2) { [0]=> string(5) "sh1sh" [1]=> string(5) "sh1sh" } Array ( [0] => Array ( [0] => sh1sh [1] => sh1sh ) )
Output for 5.4.10 - 5.6.28
Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 Notice: Array to string conversion in /in/UMbhs on line 13 array(2) { [0]=> string(5) "sh1sh" [1]=> string(5) "sh1sh" } Array ( [0] => Array ( [0] => sh1sh [1] => sh1sh ) )
Output for 5.3.20 - 5.3.29
array(2) { [0]=> string(5) "sh1sh" [1]=> string(5) "sh1sh" } Array ( [0] => Array ( [0] => sh1sh [1] => sh1sh ) )