Я пытаюсь найти свой ордер, Это мой код:
<?php
$file = 'order.dat';
$searchfor = '177';
// the following line prevents the browser from parsing this as HTML.
header('Content-Type: text/plain');
// get the file contents, assuming the file to be readable (and exist)
$contents = file_get_contents($file);
// escape special characters in the query
$pattern = preg_quote($searchfor, '/');
// finalise the regular expression, matching the whole line
$pattern = "/^.*$pattern.*\$/m";
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){
echo "Found matches:\n";
echo implode("\n", $matches[0]);
}
else{
echo "No matches found";
}
теперь, например, мой order.dat
файл содержит данные
175|RC456456456|54156456465|109$
176|RC456456456|54156456465|177$
177|RC456456456|54156456465|129$
178|RC456456456|54156456465|129$
теперь, когда я ищу 177, у меня есть такой результат: -
Found matches:
176|RC456456456|54156456465|177$
177|RC456456456|54156456465|129$
Но я хочу найти 177 только для моей первой строки
Я хочу, чтобы мой результат был таким, он совпадает только с моей 1-й строкой не для всех 4 переменных
177|RC456456456|54156456465|129$