如何从 dat 文件中获取日期(“Ymd”)
我想以(“Ymd”)格式获取日期
。dat 文件包含以下数据,这里
3rd column is date
177|RC456456177|1314160971|129$
178|RC456456456|1314167971|177$
179|RC456456456|1314130971|157$
180|RC456456456|1314260971|147$
我使用它来获取值
if($_POST['ordernum']==="")
{
$blank="Blank text box detected";
}
elseif (isset($_POST["ordernum"]))
{
$file = 'order.dat';
$searchfor = $_POST["ordernum"];
$contents = file_get_contents($file);
// escape special characters in the query
$pattern = preg_quote($searchfor,'/');
$pattern = "/^$pattern.*$/m";
if(preg_match_all($pattern, $contents, $matches)){
$result = implode("", $matches[0]);
$results = explode("|", $result);
$settings->tid = $results[1];
//echo $settings->tid;
}
else{
$res="No result found";
// echo $res;
}
}
I want to fetch my date in ("Y.m.d") format
.dat file contains the following data, here
3rd column is date
177|RC456456177|1314160971|129$
178|RC456456456|1314167971|177$
179|RC456456456|1314130971|157$
180|RC456456456|1314260971|147$
I am using this to fetch the value
if($_POST['ordernum']==="")
{
$blank="Blank text box detected";
}
elseif (isset($_POST["ordernum"]))
{
$file = 'order.dat';
$searchfor = $_POST["ordernum"];
$contents = file_get_contents($file);
// escape special characters in the query
$pattern = preg_quote($searchfor,'/');
$pattern = "/^$pattern.*$/m";
if(preg_match_all($pattern, $contents, $matches)){
$result = implode("", $matches[0]);
$results = explode("|", $result);
$settings->tid = $results[1];
//echo $settings->tid;
}
else{
$res="No result found";
// echo $res;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
那应该有效。华泰
That should work. HTH
请注意(这对我的示例不起作用),作为最佳实践,您通常应该转义 PHP 中双引号字符串内的所有
$
。As a note (this won't work for my example), you should generally escape all
$
inside of double-quoted strings in PHP as a best practice.根据您上面发布的代码,这应该可以解决问题。
Based on the code you posted above, this should do the trick.