Skip to content

Instantly share code, notes, and snippets.

@hellojinjie
Created October 8, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hellojinjie/54b4432fffaf0c67b176 to your computer and use it in GitHub Desktop.
Save hellojinjie/54b4432fffaf0c67b176 to your computer and use it in GitHub Desktop.
<?php
function getTaobaoURLFromShortURL($shortURL)
{
$contents = file_get_contents($shortURL);
$pattern = '/d="J_Url" value=\'(.+)\'>./';
preg_match($pattern, $contents, $matches);
return urldecode($matches[1]);
}
function getItemIdFromURL($itemURL)
{
$pattern = '/&id=(\d+)/';
preg_match($pattern, $itemURL, $matches);
return $matches[1];
}
function getInfoFromShareMessage($message)
{
$split = explode('淘宝商品:', $message);
$partial = explode(' ', $split[1]);
return array('title'=> $partial[0], 'shortURL'=> $partial[1]);
}
$shareMessage = "淘宝商品:2015欧美早秋新款女重工钉珠七分袖修身荷叶摆鱼尾裙显瘦连衣裙女 http://b.mashort.cn/S.Ziyfjv?sm=2b65ea (👉👉👉复制整段信息,打开手机淘宝可直接访问👈👈👈) ";
$item = getInfoFromShareMessage($shareMessage);
$shortURL = $item['shortURL'];
$itemURL = getTaobaoURLFromShortURL($shortURL);
print_r($itemURL);
echo "\n";
print_r(getItemIdFromURL($itemURL));
echo "\n";
print_r($item['title']);
echo "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment