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 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题