Search code examples
phplisttextextractcpu-word

How to extract these texts?


I want to extract this elements from this text:

Thu, Nov 12, 2020 at 12:15 PM Thu, Nov 12, 2020 at 12:15 PM [email protected] [email protected] Thu, Nov 12, 2020 at 12:15 PM To: [email protected], [email protected] 109/06 Fornistekkur 11 MBL. did not come. - Elisabet Kemp [email protected] [email protected] Thu, Nov 12, 2020 at 12:15 PM To: [email protected], [email protected] 109/06 Fomistekkur 8 MBL. did not come. - Sæmundur Guðmundsson [email protected] [email protected] Thu, Nov 12, 2020 at 12:44 PM To: [email protected], [email protected]

Is it possible somehow?

Maybe someone have idea how to extract highlighted text only this from .txt file with php?


Solution

  • Here's a start, hope helps...

    $str = "Thu, Nov 12, 2020 at 12:15 PM Thu, Nov 12, 2020 at 12:15 PM [email protected] [email protected] Thu, Nov 12, 2020 at 12:15 PM To: [email protected], [email protected] 109/06 Fornistekkur 11 MBL. did not come. - Elisabet Kemp [email protected] [email protected] Thu, Nov 12, 2020 at 12:15 PM To: [email protected], [email protected] 109/06 Fomistekkur 8 MBL. did not come. - Sæmundur Guðmundsson [email protected] [email protected] Thu, Nov 12, 2020 at 12:44 PM To: [email protected], [email protected]";
    
    
     $pattern = array ("/\d{3}\/\d{2} [a-zA-Z0-9]* [0-9]{1,2}/");
     $replacement =  array ('<strong>$0</strong>');
    
     echo preg_replace($pattern, $replacement, $str);
    

    If you wish to extract....

    $pattern = "/\d{3}\/\d{2} [a-zA-Z0-9]* [0-9]{1,2}/";
    
    $matches = array();
    preg_match_all ($pattern, $str, $matches);
    
    print_r($matches);