search
Homephp教程php手册PHP实例函数:获取淘宝商品价格

PHP实例函数:获取淘宝商品价格

Jun 13, 2016 am 11:40 AM
phpfunctionProduct priceExampleregularTaobaoofSuddenObtainexpression

这几天在看正则表达式的时候突然觉得正则表达式非常有意思啊,做了很多有意思的东西。突发奇想的觉得可以用正则表达式获取淘宝宝贝页面中的价格,所以就做了这一个函数了,调用时只需要填写入淘宝的链接就可以返回当前宝贝页面中的价格了,这的是非常的方便了。

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('淘宝宝贝地址');

直接调用函数并且填写入淘宝网的宝贝地址即可。

这个函数对于商品比价,或者是价格录入等等都是非常有帮助的呢。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

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

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment