Amazon Goods URL;
$url _array = [
' Https://www.amazon.com/dp/B073CNGGWR?aaxitk=Wthh1MTV7dbwcbCGO506iw&pd_rd_i=B073CNGGWR&pf_rd_m= Atvpdkikx0der&pf_rd_p=3930100107420870094&pf_rd_s=desktop-sx-top-slot&pf_rd_t=301&pf_rd_i=tx &hsa_cr_id=8370788670301&sb-ci-n=asinimage&sb-ci-v=https%3a%2f%2fimages-na.ssl-images-amazon.com% 2fimages%2fi%2f41pnbzhboel.jpg&sb-ci-a=b073cnggwr ',
' Https://www.amazon.com/Mysticbags-Waterproof-Backpack-Primary-Students/dp/B071D37XQD/ref=sr_1_1_sspa?s= apparel&ie=utf8&qid=1534865412&sr=1-1-spons&nodeid=7141123011&psd=1&keywords=book& Psc=1 ',
];
Gets the string from https://to/dp/through the regular;
It is implemented by the following code:
$preg = '/https:\/\/www. [^\s*]*\/dp\/\w* (\/|\?) /I ';
foreach ($url _array as $index = $v)
{
Preg_match_all ($preg, $v, $matche);
$url _result_data[] = $matche [0][0];
}
DD ($url _result_data);
Echo:
Array:2 [ 1 => "https://www.amazon.com/dp/B073CNGGWR?" 2 => "https://www.amazon.com/Mysticbags-Waterproof-Backpack-Primary-Students/dp/B071D37XQD/"]
Regular related attention knowledge points:
\ for Escape
\s any one character except for whitespace characters
* Match 0~n times the atoms in front of it,
\w matches any number, letter, underscore equivalent to [0-9a-za-z_]
\w Matching non-\w
| Match two or more branch selections
() is used as a pattern unit, which makes large atoms of multiple atoms, and is used as a separate unit. Eg:/(very) *good/can match good, very good, very very very good, or very very ... good,
. Matches any one of the characters in the target, including non-printable characters, and matches any one character except the line break. Eg:/a.b/matches a string of any character between A and B for example: AXB,ATB,ACB,AZB, etc.
PHP regular Match URL