접근 방식을 조금 변경하십시오. 검색어와 분리기를 단일 문자열로 저장하는 대신 두 변수를 사용하십시오.
$sep = '--->';
$searchfor = '124';
$pattern = "/^$sep\s+($searchfor\d+)\s+.*/m";
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){
echo implode(' ', $matches[1])."\n";
}
출력 :
12455 12477