0

i want to preg_match "8t5562g" of the second sentence where title has a word similar to "Music"

</div><div class="content"><h3 class="title "><a href="9JGl134" class="ellipsis" data-sessionlink="vij0JFIDY2Jj"  title="Drama_Live - Drama Live " rel="prefetch" dir="ltr">#Drama_Live - Drama Live</a></h3>

    </div><div class="content"><h3 class="title "><a href="8t5562g" class="ellipsis" data-sessionlink="vdshds4452Jj"  title="Music_Live - Music Live " rel="prefetch" dir="ltr">#Music_Live - Music Live</a></h3>

Tried this but didn't worked

$likes = preg_match("'herf=\"(.*?)\"'si", $data, $matches);
$like = "($matches[1])";       
print $like;

but it gives me href of first sentence not what i want. Any Idea ?

Dr.Mezo
  • 807
  • 3
  • 10
  • 25
  • 1
    Why don't you use a DOM parser? – The fourth bird Mar 09 '18 at 15:28
  • 3
    Is it time for [*the* answer](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) again? – CD001 Mar 09 '18 at 15:28
  • 1
    `"'herf=\"(.*?)\"'si"` ... are you really using apostrophes as delimiters? ... and you probably want `href` rather than `herf` ... – CD001 Mar 09 '18 at 15:31

1 Answers1

0

Try this:

$likes = preg_match("#href=\"(.*?)\".*usic#si", $data, $matches);

The first group will be your result

iwex
  • 384
  • 3
  • 17