- var_dump: documentation ( source)
- preg_match: documentation ( source)
- print_r: documentation ( source)
- str_replace: documentation ( source)
- explode: documentation ( source)
- trim: documentation ( source)
- array_unique: documentation ( source)
<?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);