<?php $m = ' <div>A</div> <di>B</div> <div>C</div> <div>A</div> <div>B</div> <div>C</div> <div>A</div> <div>B</div> <div>interference</div> <div>C</div> <div>A</div> <di>B</div> <div>C</div> <div>A</div> <div>B</div> <div>interference</div> <div>more interference</div> <div>C</div> '; //want to get the first, second and third //more like i want to get just the ones with no interference (capture the one with just 3 div) foreach (preg_split('/\n/', $m) as $line) { $pattern = '/<.*>(A)<.*> <.*>(B)<.*> <.*>(C)<.*>/'; var_dump( preg_replace($pattern, '$1$2 $3', $line)); }
You have javascript disabled. You will not be able to edit any code.