PHP实例函数:获取淘宝商品价格
这几天在看正则表达式的时候突然觉得正则表达式非常有意思啊,做了很多有意思的东西。突发奇想的觉得可以用正则表达式获取淘宝宝贝页面中的价格,所以就做了这一个函数了,调用时只需要填写入淘宝的链接就可以返回当前宝贝页面中的价格了,这的是非常的方便了。
function taoBaoJiaGe($url){ preg_match('/<strong id="J_StrPrice" >\d+.\d{2}/',file_get_contents($url),$jiaGe); //正则表示获取包含价格的 HTML 标签 preg_match('/\d+.\d{2}/',$jiaGe[0],$jiaGe); //正则表达式再次从结果中分离价格。 return $jiaGe[0]; //返回价格 }
首先先在代码中引入自定义函数 taoBaoJiaGe(); 那么需要调用的时候怎么办,很简单。
taoBaoJiaGe('淘宝宝贝地址');
直接调用函数并且填写入淘宝网的宝贝地址即可。
这个函数对于商品比价,或者是价格录入等等都是非常有帮助的呢。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment