The server responds with the following markup.

<p class="hvl-post-author"> <a href="https://example.com" title="Источник" target="_blank"> site our</a>(site our) <span class="hvl-post-author-separ">→</span> </p> 

how to get the text inside the tag a

  preg_match_all('#<p class="hvl-post-author"><a(.?)+>(.+?)</a>#is', $arr); print_r($arr); 
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

Use an HTML parser for this; regulars are not suitable for this:

 $str = <<<HTML_CODE <p class="hvl-post-author"> <a href="https://example.com" title="Источник" target="_blank"> site our</a>(site our) <span class="hvl-post-author-separ">→</span> </p> HTML_CODE; $html = str_get_html($str); var_dump($html->find('a', 0)->innertext); // site our 
  • And why are regulars not suitable? - Bookin
  • @Bookin regular expressions are not suitable for languages. The design may change, doing the same thing, and the regular breaks down. - user207618
  • one
    Well, if the markup is changed, then any code tied to it will break, even though it is a regular routine, even a parser. - Bookin

Specifically in your example:

  • preg_match_all takes three parameters preg_match_all(шаблон, где ищем, куда сохраним результат)
  • In your regular calendar between the tags <p> and <а> there should not be any characters, in the text there should be at least a line break

Even your regular expression option will work when you consider these two points.

preg_match_all('#<p class="hvl-post-author">.*<a(.?)+>(.+?)</a>#is', $str, $arr);

http://sandbox.onlinephpfunctions.com/code/d72b36fb2fd2a2522648c15ee8dfb24be2583b11