<?php $t ='<body> <item>abc</item> <item>def</item> unparsable rest </body>'; $filtered = array_filter(explode("\n", $t), function($line) { $line = trim($line); return $line[0] == '<' && substr($line, -1) == '>'; }); $result = implode("\n", $filtered); echo $result;
You have javascript disabled. You will not be able to edit any code.