2017-01-18 50 views
2

私は多くの同様のURLを持っています。そして、私はそれらから文字列を取得したい。PHP - PHPでpreg_matchを使用して文字列から文字列を取得

例えばURLは次のとおりです。 - 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

そして、私は(引用符なし)「B01LF7Y0S4」の値を取得したい

我々は考えることができます「/ DP /」開始点と非常に最初の「/ "/ dp /"の後に "end"を付けます。

ありがとうございます。

+1

可能な複製(http://stackoverflow.com/questions/4736/learn-regular-expressions) – Biffen

+0

https://regex101.com/r/chirlr/1 – smoqadam

答えて

0

あなたはこれを試すことができます。

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

Explanation

サンプルコード:[正規表現を学ぶ]の

$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]; 
+0

ありがとうMaverick_Mrt。それは私の問題を解決しました。 :) –

関連する問題