-1

I want to grab any data between these two div headers, and the code below should work, is there something I am not seeing?

preg_match_all('$\<div class\=\"productDescriptionWrapper\"\>(.*?)\<div class\=\"emptyClear\"\>$', $source, $match);

Thanks in advance!

Visin
  • 129
  • 8
  • 8
    O GOD IT'S TERRIBLE. sorry. Please refer to http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – Cam Oct 29 '11 at 02:17
  • 1
    You have to start with `^` to indicate start of the string. `$` should be used to indicate end of the string. Also, question mark after * seems to be awkward. – user482594 Oct 29 '11 at 02:17
  • "I think that using a regular expression to process XML when there are plenty of good XML parsers out there is a bad idea." – chown Oct 29 '11 at 02:20
  • I explained exactly what was needed, what is not clear about 'grab any data between two div headers'? – Visin Oct 29 '11 at 02:21
  • Show us some sample data that this regex is supposed to work on. It works fine as long as the data matches the regex: http://rubular.com/r/FOhXe2Us9n Also, use an XML parser! – deceze Oct 29 '11 at 02:34
  • 1
    @user482594 that question mark means non-greedy matching. It's not at all "awkward". – Chris Eberle Oct 29 '11 at 02:54
  • Also the dollar symbols are to mark the beginning and end of the regex. Normally you'd see a `/` here, but for reasons I don't fully grasp the OP decided to use dollar signs. – Chris Eberle Oct 29 '11 at 02:59
  • In fact, "awkward" is a good word for *that* (i.e., using `$` as the regex delimiter). But I wouldn't use `/` either; it's too common in HTML. Also, `<`, `>`, `=` and `"` have no special meaning in regexes, so none of those backslashes are needed. – Alan Moore Oct 29 '11 at 08:05

1 Answers1

1

Cory, typically you should be using DOMDocument to do this. Using regex to parse html is not considered good practice because it contains so many hidden follies and overcomplicates.

http://php.net/manual/en/class.domdocument.php

dqhendricks
  • 19,030
  • 11
  • 50
  • 83