How to use preg_match_all in this section?

0
<div>
  <span class="dark_text">Type:</span>
  <a href="https://myanimelist.net/topanime.php?type=var1">var2</a></div>~

I need to make preg match all the variable var2 regardless of what is written in var 1

example:

preg_match_all('!<a href="https://myanimelist.net/topanime.php?type=var1">(.*?)</a></div>',$result,$match);
    
asked by anonymous 03.06.2017 / 18:19

1 answer

1

This response is based on the question before editing .

Just use:

/<a href="https:\/\/myanimelist.net\/topanime.php\?type=var1">(.*?)<\/a><\/div>/

It is necessary to escape / and ? , otherwise it will not work. So it will get the (.*?) that is between the string.

preg_match_all('/<a href="https:\/\/myanimelist.net\/topanime.php\?type=var1">(.*?)<\/a><\/div>/',$result,$match);


var_dump($match);

Result:

array(2) {
  [0]
  array(1) {
    [0]
    string(71) "<a href="https://myanimelist.net/topanime.php?type=var1">var2</a>"
  }
  [1]
  array(1) {
    [0]
    string(4) "var2"
  }
}

Also consider looking for DOMDocument , so you can find other options.

    
03.06.2017 / 19:24