dongyuhui0418 2013-08-22 14:14
浏览 25
已采纳

使用php将跟踪代码添加到CSV文件的每一行中的第一个链接实例

I would like to

  1. download a csv file from a webserver
  2. add a tracking code to the first instance of a link in each line of the csv file.
  3. upload the file to a ftp server

    How could I do that using php?

The important part is no.2 as I have difficulties figuring out the functions and regular expressions to use for modifying the links. Downloading and uploading the file I can figure out myself.

example

input:

ID, text1, link1, text2, text3, link2
1234, something, http://www.example.com/a/b/c, "lorem", "ipsum", http://www.example.com/image.gif
1235, something, http://www.example.com/dddd, "lorem", "ipsum", http://www.example.com/image.gif
1236, something, http://www.example.com/e/f/g/h, "lorem", "ipsum", http://www.example.com/image.gif

output:

ID, text1, link1, text2, text3, link2
1234, something, http://www.example.com/a/b/c?tracking_code=1&tr2=2, "lorem", "ipsum", http://www.example.com/image.gif
1235, something, http://www.example.com/dddd?tracking_code=1&tr2=2, "lorem", "ipsum", http://www.example.com/image.gif
1236, something, http://www.example.com/e/f/g/h?tracking_code=1&tr2=2, "lorem", "ipsum", http://www.example.com/image.gif
  • 写回答

1条回答 默认 最新

  • doutang6130 2013-08-22 14:21
    关注

    lets assume your getting each line using fgetcsv

    $line = fgetcsv($fp);
    $line[2] = $line[2] . "?tracking_code=1&tr2=2";
    $data[] = $line;
    
    ......
    
    foreach ($data as $line) {
        fputcsv($fp, $line);
    }
    

    The code i posted is abstract and assumes your familiar with how to iterate through a csv file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么