我想搜索我的訂單ID,這是到目前爲止我的代碼:搜索從dat文件
<?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$
現在時我searchfor 177我有這樣的結果: -
Found matches:
176|RC456456456|54156456465|177$
177|RC456456456|54156456465|129$
但我想搜索177我的第一個字符串onl Ÿ
我想我的結果是這樣,它唯一的不匹配上的所有4個變量
177|RC456456456|54156456465|129$
:)我希望我的結果是這樣的,177 | RC456456456 | 54156456465 | 129 $ – John
@David:更新了答案。 – codaddict
:)謝謝你很多...可以üPLZ給我提供任何研究的鏈接 – John