Sadece bir dosya adı belirtin, dosyanın içeriğini alın ve dosya içeriğiyle normal ifadeleri eşleştirin.
$fileName = '/path/to/file.txt';
$fileContents = file_get_contents($fileName);
$searchStr = 'I want to find this exact string in the file contents';
if ($fileContents) { // file was retrieved successfully
// do the regex matching
$matchCount = preg_match_all($searchStr, $fileContents, $matches);
if ($matchCount) { // there were matches
// $match[0] will contain the entire string that was matched
// $matches[1..n] will contain the match substrings
}
} else { // file retrieval had problems
}
Not: Aşağıdaki kodum numunesi ile ilgili daha detaylı bilgi için this ve this görün Bu bakılmaksızın bir linux kutusunda konum olup olmadığına çalışacaktır.
Teşekkürler! Bu bir charmed gibi çalıştı, ancak bir satırda belirli bir "kod" nasıl alabilirim? Bir satır şöyle: TME: ... | UID: ... | FNE: ... | MSG: ... | IPA: ... '. "Kod" örneğin "UID" dir. – Erik
Eğer doğru bir şekilde anlıyorsam, eğer (strpos ($ line, '| UID:')! == false) 'ihtiyacınız olanı yapabilir. – ghbarratt
Eğer yankı nasıl olursa olsun? – Erik