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
  • 68,531
  • 11
  • 88
  • 149
Sharique Anwer
  • 81
  • 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];
Rizwan M.Tuman
  • 9,424
  • 2
  • 24
  • 40