这是一个vine视频示例https://vine.co/v/bjHh0zHdgZT。我怎么才能只得到它的描述?
假设我有视频的id,这是bjHh0zHdgZT,我需要得到vine的描述为我的PHP为基础的网站。
谢谢。
发布于 2013-06-21 18:56:06
也许你可以解析页面的meta标签?
vine页面的来源:
<meta property="twitter:card" content="player">
<meta property="twitter:title" content="Jethro Ames's post on Vine">
<meta property="twitter:description" content="SquareVine 1 #howto #favthings #loop">使用file_get_contents和preg_match从php获取描述:
<?php
$url = "https://vine.co/v/bjHh0zHdgZT";
$data = file_get_contents($url);
preg_match('~<\s*meta\s+property="(twitter:description)"\s+content="([^"]*)~i', $data, $matches);
print_r($matches);
if ( isset($matches[2]) ) {
$description = $matches[2];
}
?>输出:
Array
(
[0] => <meta property="twitter:description" content="SquareVine 1 #howto #favthings #loop
[1] => twitter:description
[2] => SquareVine 1 #howto #favthings #loop
)你的描述是$matches2。注意控制这些内容(html实体、sql转义等)。
https://stackoverflow.com/questions/17229273
复制相似问题