0

I am trying to get the 6 or 7 number sequence and put it in the urls array.

<a href="/product/view/4539922/" class="raw_clafd">

However I am having a problem with the regex below.

preg_match_all('/<a\s+href="\.\/view\/(\d{6,7})\/"  class="raw_clafd">/', $str, $urls);

What am I missing? Thank you

EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179

2 Answers2

1

You cannot match /product with \.

You can use:

preg_match_all('#<a\s+href="/product/view/(\d{6,7})/"\s+class="raw_clafd">#', $str, $urls);

But I really believe you should consider using DOM parser.

anubhava
  • 761,203
  • 64
  • 569
  • 643
0

You can get the value after /view/ just by using

/\/view\/(\d{6,7})/
aelor
  • 10,892
  • 3
  • 32
  • 48