php - Small modification to regex to make it work?

556

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

674

Answer

Solution:

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.

487

Answer

Solution:

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

/\/view\/(\d{6,7})/

People are also looking for solutions to the problem: required field javascript sees the label for dropdown in php as a selected option

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.