5
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?

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.