Guys, tell me how to parse the file to get a string Example text:

Text Text Text Text Email: mail.mail@mail.ru Text Text Text Text

you need to get the email in this file, that is, to receive the data after the word "Email:"

    1 answer 1

    To do this, you can use regular expressions. For example, you can build on the following script:

    <?php //$str = 'Текст Текст Текст Текст Email: mail.mail@mail.ru Текст Текст Текст Текст '; $str = file_get_contents('text.txt'); $pattern = '/Email:\s+([^\s]+)\s/'; preg_match_all($pattern, $str, $out); echo '<pre>'; print_r($out[1]); 
    • Thank you, I have a bad time with regulars ( - lxxnutsxxl
    • @cheops to take part in the conversation :) - /Email:\s+(\S+)/ - splash58
    • and if I have a lot of files in the folder on the host which I need to pull out this mail, how easier is it to send?)) - lxxnutsxxl
    • @lxxnutsxxl, are the files large? If you combine them into the memory of the script fit (usually 128MB)? In principle, you can loop around, collect their contents into one big line and feed it to a regular expression. - cheops 5:56 pm
    • 2
      @lxxnutsxxl In the simplest case, you can run through the glob () function and save all the contents in one line and then feed it to the regular $ str = ''; foreach (glob ("*. txt") as $ filename) {$ str. = file_get_contents ($ filename); } - cheops