在一个列中我有三个值...如何单独获取它们

时间:2014-12-17 11:10:19

标签: php mysql arrays

<table>
<tr><td>Pam Date:23-11-2014 Time: 02:18:00 </td></tr>
<tr><td>Sam Date:24-11-2014 Time: 04:00:00 </td></tr>
<tr><td>Julie  Date:26-11-2014 Time: 06:10:00 </td></tr>
<tr><td>Remo Date:27-11-2014 Time: 04:25:00 </td></tr>
<tr><td>Woods Date:27-11-2014 Time: 03:40:00 </td></tr>
</table>

所有这些值都在同一列中,我只需要date值。

1 个答案:

答案 0 :(得分:0)

这应该适合你:

<?php

    $input = "<tr><td>Pam Date:23-11-2014 Time: 02:18:00 </td></tr>
            <tr><td>Sam Date:24-11-2014 Time: 04:00:00 </td></tr>
            <tr><td>Julie  Date:26-11-2014 Time: 06:10:00 </td></tr>
            <tr><td>Remo Date:27-11-2014 Time: 04:25:00 </td></tr>
            <tr><td>Woods Date:27-11-2014 Time: 03:40:00 </td></tr>
            ";

    preg_match_all("/Date:\s?(\d{2}-\d{2}-\d{4})\s?/", $input, $output);
    print_r($output);

?>

输出:

Array
(
    [0] => Array
        (
            [0] => Date:23-11-2014 
            [1] => Date:24-11-2014 
            [2] => Date:26-11-2014 
            [3] => Date:27-11-2014 
            [4] => Date:27-11-2014 
        )

    [1] => Array
        (
            [0] => 23-11-2014
            [1] => 24-11-2014
            [2] => 26-11-2014
            [3] => 27-11-2014
            [4] => 27-11-2014
        )

)