我在xls表中有一个Facebook链接列表,其Facebook id是这样的。

当我浏览这些链接时,意味着如果我使用id www.facebook.com/7500访问Facebook
我得到的https://www.facebook.com/davesachs/类似于下面的urls
所以我的问题是,我想用PHP来做这件事,我有一个PHP页面,它从xls表中读取数据,我的代码如下:
require_once 'src/SimpleXLSX.php';
if ( $xlsx = SimpleXLSX::parse('fburl.xlsx') ) {
$rows= $xlsx->rows();
foreach($rows as $data){
echo $data[0].'<br>';
}
} else {
echo SimpleXLSX::parseError();
}它返回所有id相同的脸书链接,我像www.facebook.com/7500一样传递,但我希望它返回的网址/链接的配置文件作为https://www.facebook.com/davesachs/,如果这是可能的,请帮助我做到这一点。
发布于 2021-01-28 16:02:28
你可以借鉴here的经验,做一些类似的事情
<?php
require_once 'src/SimpleXLSX.php';
if ( $xlsx = SimpleXLSX::parse('fburl.xlsx') ) {
$rows= $xlsx->rows();
foreach($rows as $data){
getRedirectedUrl($data[0]);
}
} else {
echo SimpleXLSX::parseError();
}
function getRedirectedUrl($link){
$url=$link;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Must be set to true so that PHP follows any "Location:" header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$a = curl_exec($ch); // $a will contain all headers
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // This is what you need, it will return you the last effective URL
// Uncomment to see all headers
/*
echo "<pre>";
print_r($a);echo"<br>";
echo "</pre>";
*/
echo $url; // Voila
}
?>https://stackoverflow.com/questions/65932998
复制相似问题