如何从行php打印字符串?

时间:2015-12-20 16:49:52

标签: php

我需要一些帮助 我仍然是PHP的新手 我需要如何从这个结构中的行中对字符串进行排序,请

A: name pass { date=xx-xx-xxxx ; name=something ; email=xxx@xx.xx }

我只需从此行获取未知日期 xx-xx-xxxx减少一天。 例如 2016年12月29日,减少之后将是这样的:28-12-2016

原始代码:

<?php
$file_handle = fopen("file.txt", "r");
$email = "test@gmail.com"; 


while (!feof($file_handle)) {
   $line = fgets($file_handle);

     if (strpos($line, "$email") !== false)
        {
           $fdate = preg_match('/date=(\d{1,2}-\d{1,2}-\d{4})/',$line , $date);
           $adate = date('d-m-Y', (strtotime($date[1]) - 86400));
           $data = explode(" ", $line);
           echo $adate ;
           echo "\n";
        }
}
fclose($file_handle);

?>

1 个答案:

答案 0 :(得分:0)

这个怎么样:

Dim NotUsedRB As New RadioButton
        With NotUsedRB
            .Content = "Not Used"
            .ToolTip = "This mailing address is not used"
            .GroupName = "MailingRB"
            .Name = "Mailing_NotUsedRB"
        End With
        RegisterControl(Customer_Grid, NotUsedRB)
        vToolbar.Items.Add(NotUsedRB)
        vToolbar.Items.Add(TS_Separator)

        Dim StatementsRB As New RadioButton
        With StatementsRB
            .Content = "Statements"
            .ToolTip = "Mailing address used for statements"
            .GroupName = "MailingRB"
            .Name = "Mailing_StatementsRB"
        End With
        RegisterControl(Customer_Grid, StatementsRB)
        vToolbar.Items.Add(StatementsRB)
        vToolbar.Items.Add(TS_Separator)

        Dim FinesRB As New RadioButton
        With FinesRB
            .Content = "Fines"
            .ToolTip = "Mailing address for violation fines"
            .GroupName = "MailingRB"
            .Name = "Mailing_FinesRB"
        End With
        RegisterControl(Customer_Grid, FinesRB)
        vToolbar.Items.Add(FinesRB)
        vToolbar.Items.Add(TS_Separator)

输出:

$string = 'A: name pass { date=29-12-2016, ; name=something ; email=xxx@xx.xx }';
preg_match('/date=(\d{1,2}-\d{1,2}-\d{4})/', $string, $date);
echo date('d-m-Y', (strtotime($date[1]) - 86400));

这会将日期拉到变量,然后减去一天(86400秒)。

Regex101演示:https://regex101.com/r/dK8aN1/1