2

I have many similar URLs. And i want to get a string from them.

For example the URL is:- http://www.amazon.in/Sinew-Nutrition-Decaffeinated-Unroasted-Management/dp/B01LF7Y0S4/ref=sr_1_1?ie=UTF8&qid=1484716249&sr=8-1&keywords=green+coffee+beans

And I want to get "B01LF7Y0S4" value (without quotes)

We can consider "/dp/"the start point and the very first "/" after "/dp/" the end point.

Thanks in advance.

Alan Moore
  • 71,299
  • 12
  • 93
  • 154
Sharique Anwer
  • 131
  • 1
  • 12

1 Answers1

0

You can try this:

\/dp\/([^\/]*)\/

Explanation

Sample Code:

$re = '/\/dp\/([^\/]*)\//';
$str = 'http://www.amazon.in/Sinew-Nutrition-Decaffeinated-Unroasted-Management/dp/B01LF7Y0S4/ref=sr_1_1?ie=UTF8&qid=1484716249&sr=8-1&keywords=green+coffee+beans';
preg_match_all($re, $str, $matches);
echo $matches[1][0];
Mustofa Rizwan
  • 10,009
  • 2
  • 25
  • 42