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,021
  • 16
  • 87
  • 172

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
  • 713,503
  • 59
  • 514
  • 593
0

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

/\/view\/(\d{6,7})/
aelor
  • 10,430
  • 3
  • 30
  • 46