Php 文件\u获取\u内容和变量echo
我试图弄明白这一点,我想从变量或Php 文件\u获取\u内容和变量echo,php,file-get-contents,Php,File Get Contents,我试图弄明白这一点,我想从变量或旁边的任何php代码中回显信息http://vine.co/v/“在第3行下有人能帮我吗 我的代码: <?php $vine = file_get_contents('http://vine.co/v/', false, $test); $test = "haiKqBFA9Yw"; preg_match('/property="og:image" content="(.*?)"/', $vine, $matches); $url = $matches[1]
旁边的任何php代码中回显信息http://vine.co/v/“
在第3行下
有人能帮我吗
我的代码:
<?php
$vine = file_get_contents('http://vine.co/v/', false, $test);
$test = "haiKqBFA9Yw";
preg_match('/property="og:image" content="(.*?)"/', $vine, $matches);
$url = $matches[1];
$url = str_replace( 'https://', 'http://', $url );
$url = str_replace( 'versionId=', '', $url );
$img = $url;
$url = substr($img, 0, strpos($img, "?"));
echo $url;
返回给定url中所有打开的图形元的简单函数:
function getUrlOpenGraphMetas($url) {
$dom = new DOMDocument;
@$dom->loadHTMLFile($url);
$xpath = new DOMXPath($dom);
$metas = array();
if (!$entries = $xpath->query('//html/head/meta[starts-with(@property, "og:")]')) return $metas;
foreach ($entries as $entry) $metas[$entry->getAttribute('property')] = $entry->getAttribute('content');
return $metas;
}
使用:
根据文档,文件中的第三个参数需要是一个资源。检查第四个例子:好的,谢谢你的帮助。对于那些投票反对的人,我对php还是新手,我做了很多研究,只是需要帮助理解。谢谢你的回答Glavic,但是当我插入你的代码时,它返回了这个错误Parse error:syntax error,unexpected'['在C:\UwAmp\www\tos.php的第4行
对不起,php>=5.4语法;)我将数组从[/code>更改为array()
。现在试试。啊,对不起,我没有看到你的更新代码。你是我的英雄哈哈。谢谢你的帮助:3没问题,很高兴我能帮忙。
$metas = getUrlOpenGraphMetas('https://vine.co/v/haiKqBFA9Yw');
$img = $metas['og:image'];
if (($pos = strpos($img, '?')) !== false) $img = substr($img, 0, $pos);
$img = str_replace('https://', '//', $img);
echo $img;