In PHP how to limit regex search to a div html class?

Asked

Viewed 33 times

0

In php, how to mount a regex (to use with preg_match_all) the link on href and the title between >(.*?)< ONLY IN class "container" (15 occurrences). In the source, without the limitation to a class are 60 occurrences found. I know that using Regex with html is not recommended, it occurs that I find regex more practical to mount. I read in stackoverflow in English a suggestion to capture the block inside the tag, I tried to replicate separating link and title, but it did not work.

<div class="container">
<li class="nav-item cat-item-19"><a href="http://www.exemplo.com/1">teste</a>
</div>
  • It might be interesting for you to read: Why Regex should not be used to handle HTML?

  • @Andersoncarloswoss, yes I had read in the American version. To be honest this is my first real obstacle with regex in html. I always capture the data without problems. I just wanted to know if - with regex - it would be possible to do this limitation.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.