Ben
Ben

Reputation: 62366

Regex whitespace

preg_match('/<div class="prices">/s<h3>(.+?)<\/h3>/is', $response, $matches);

There's whitespace and potentially new lines between the prices div and the h3 tag. How do I use /s to match that?

Upvotes: 5

Views: 4852

Answers (1)

Mark Byers
Mark Byers

Reputation: 838116

You don't use /s, you use \s*.

  • It's a backslash (\), not a slash (/).
  • The * afterwards means that it matches zero or more whitespace characters.

Also, please consider using an HTML parser if you are trying to find HTML tags. A proper HTML parser will be able to correctly handle whitespace, HTML comments and other features of HTML that your regular expression cannot handle.

Upvotes: 8

Related Questions