我的Excel表格中有一些URL列表,如下所示
现在我想逐个加载所有这些URL来跟踪和获取它的内容和文本,这些内容和文本位于"?"之后。在像这样的新专栏
utm_source ABC utm_medium XYZ utm_content PQR utm_campaign JKL
使用PHP解析并且我不想使用CURL,因为我已经在Excel表格中使用了URL,所以只想将其加载到PHP脚本中并从中获取文本.. < / p>
我对此一无所知,所以如果有人可以帮助我,如果可能的话,请给我发送代码..
答案 0 :(得分:0)
file_get_contents('http://www.example.com/');
将你的网址爆炸?和&amp;获取在url中传递的参数的详细信息
答案 1 :(得分:0)
如果您尝试读取网址的值,则:
parse_str() - 将字符串解析为变量Read More
<?php
$url = "http://www.example.com/excel-add-in-google-analytics/?utm_source=ABC&utm_medium=XYZ&utm_content=PQR&utm_campaign=JKL";
parse_str($url,$values);
print_r($values);
?>
答案 2 :(得分:0)
<?php
$str = "http://www.example.com/excel-add-in-google-analytics/?utm_source=ABC&utm_medium=XYZ&utm_content=PQR&utm_campaign=JKL";
$var = parse_url($str);
parse_str($var['query'], $query);
foreach($query as $key=>$val)
{
echo $key." ".$val;
}
?>
答案 3 :(得分:0)
使用PHPExcel library阅读您的Excel文件,parse_url
提取网址的查询部分。让我详细解释一下步骤:
首先从github下载PHPExcel库(格式为.zip
)并将其解压缩到项目目录中。您的项目目录如下所示:
-PHPExcel-1.8 (your extracted library)
|--Classes
|--PHPExcel (folder)
|--PHPExcel.php
|-- (other things)
-excel.xlsx (your excel sheet)
-index.php (this is where you're going to read and process your excel sheet)
的的index.php 强>
现在阅读你的excel文件并提取所需的URL查询部分,即URL后面的文本部分,如下所示:
(将excel.xlsx
替换为您的文件名)
<?php
// Include PHPExcel.php
include 'PHPExcel-1.8/Classes/PHPExcel.php';
$inputFileName = 'excel.xlsx'; // replace excel.xlsx with your file name
// Read your Excel workbook
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}
// Get worksheet dimension
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
// Loop through each row
for ($i = 1; $i <= $highestRow; $i++){
$row = $objPHPExcel->getActiveSheet()->getRowIterator($i)->current();
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
// Loop through each cell
foreach ($cellIterator as $cell) {
$cell = $cell->getValue();
// display only the query part of the URL
echo parse_url($cell)['query'] . "<br />";
}
}
?>