This one is bit tricky , I have an array and I need to keep only certain value string inside of it
$getpositions = file("index.php");
$searchpoz = array('NEED1', 'NEED2', 'WANT THIS ALSO','ANDTHIS');
function strposa($haystack, $needles=array(), $offset=0) {
$chr = array();
foreach($needles as $needle) {
$res = strpos($haystack, $needle, $offset);
if ($res !== false) $chr[$needle] = $res;
}
if(empty($chr)) return false;
return min($chr);
}//http://stackoverflow.com/a/9220624/594423
foreach($getpositions as $key => $clearlines) {
if(strposa($clearlines, $searchpoz) == false)
unset($getpositions[$key]);
}
$positionsorder = array_values($getpositions);
print_r($positionsorder);
Array
(
[0] => i dont need this NEED1 i dont need this
[1] => i dont need this NEED2 i dont need this
[2] => i dont need this WANT THIS ALSO i dont need this
[3] => i dont need this ANDTHIS i dont need this
)
so desired output should be
Array
(
[0] =>NEED1
[1] =>NEED2
[2] =>WANT THIS ALSO
[3] =>ANDTHIS
)
notice that I need to remove everything before and after the desired value
any help is appreciated , thank you!