Help with cURL PHP for link?

Discussion in 'PHP' started by AliceW, Jan 19, 2011.

  1. #1
    
    curl_setopt($ch, CURLOPT_URL,
    'https://example.com/report.php?start=2011-01-12&end=2011-01-19');
    
    PHP:
    I am trying to access a report API and save a local copy of the report for the last week. I can do this okay but I have to change the dates in the URL above manually each day. What I would like to do is use PHP so that the date range is always the last 7 days. Is there an easy way to do this, I have been reading about strtotime and using -7 days and a bunch of other things but with my limited PHP knowledge I am not sure how to implement what I have read.

    Thanks a bunch.
     
    AliceW, Jan 19, 2011 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    Like this maybe:

    
    $todaysdate = date('Y-m-d'); 
    $sevendays = date ( 'Y-m-d', strtotime ( '-7 days' . $date ) );
    
    $url = "https://example.com/report.php?start=$sevendays&end=$todaysdate";
    
    curl_setopt($ch, CURLOPT_URL, $url);
    
    //echo $url;
    
    
    PHP:
     
    MyVodaFone, Jan 19, 2011 IP
  3. AliceW

    AliceW Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Wow, that was so fast and seems to work great as well.

    Thank you so much.
     
    AliceW, Jan 19, 2011 IP
  4. Irfi0009

    Irfi0009 Banned

    Messages:
    17,584
    Likes Received:
    33
    Best Answers:
    1
    Trophy Points:
    48
    #4
    plz help i am new so give me how can get sale link
     
    Irfi0009, Jan 19, 2011 IP