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‘, ]; // 通过正则获取 https:// 至 /dp/ 到 / 之间的字符串; 通过以下代码实现:
$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/" ] 正则相关注意知识点:\ 为转义 \S 除了空白字符以外的任何一个字符* 匹配0~n 次其前面的原子,\w 匹配任意一个数字、字母、下划线 等价于 [0-9A-Za-z_]\W 匹配非 \w| 匹配两个或多个分支选择() 作为模式单元使用,将多个原子组成大的原子,被当做一个独立的单元使用。 eg: /(very)*good/ 可以匹配 good, very good, very very very good, 或者 very very ...... good, . 匹配目标中的任何一个字符,包括不可打印字符,匹配除了换行符之外的任何一个字符。 eg: /a.b/ 匹配 a 到 b 之间有任意一个字符的字符串 例如: axb,atb,acb,azb等等
原文地址:https://www.cnblogs.com/haoxuanchen2014/p/9515194.html
时间: 2024-10-08 18:59:04