Help please write a regular expression, string:

"Фамилия</td><td>ВОТ ЭТО НАДО ВЫТАЩИТЬ</td>"

you need to pull out from the line the text "ВОТ ЭТО НАДО ВЫТАЩИТЬ"

At the same time, the "Фамилия</td><td>" and "</td>" parts are constant in all lines!

    2 answers 2

     preg_match_all('~Фамилия</td><td>(.*?)</td>~u', $text, $matches); // обратите внимание на ~u 

    or:

     preg_match_all('~<td>(.*?)</td>~u', $text, $matches); // обратите внимание на ~u 
    • What does ~ u mean? - Tolyandre
    • You wrote such regulars with the utf-8 modifier with such confidence that it became interesting to me, how do you know that the vehicle will not work with cp1251? <br> So I wouldn’t be so sure about <b> u </ b > - Zowie
    • Practice :) Usually, if people give quite a working regular expression and have problems with it - then in 90% of cases the problem is just ~ u, but the text of the regular expression itself should be in utf-8 - Alex Kapustin
     /Фамилия<\/td><td>([\W]+)<\/td>/ 
    • And how to pull out the contents ONLY? without "Last Name </ td> <td>" and "</ td> - Andrei Surzhikov
    • Remove the <b> Last Name </ b> xD <br> from the regular form; in general, in the code, simply type <br> <<pre> <code> preg_match_all ($ preg, $ match, $ matches); // look at the matches array and find what you need there ... </ code> </ pre> <br> As an alternative, preg_replace($preg, '$1', $str) ... Here we replace the old string with the required ones values, although, as it seemed to me, you need exactly the first option ... - Zowie
    • AlexWindHope, great joke) and without td / td (tags just got stuck when commenting) - Andrei Surzhikov
    • 2
      OMG why? O_o - Zowie