SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Location
    EAST COAST
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using curl to pull current temperature?

    Is it possible to pull the current weather temperature and add 1 degree to it?

    Just trying to full around with Curl for the first time and can not find much documentation on how to do something like this.

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Well, you will need to find a weather provider to do that. Something like... http://www.google.com/ig/api?weather=The+Hague

    Now, you could retrieve that information with cURL, then parse the XML to find current_conditions/temp_c, and then add 1 to that.

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Location
    EAST COAST
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well now I have that part figured out but before I post the code I have gathered.

    In example cURL returns $e=x.xxx

    When I use echo $e;
    it comes back as x.xxx

    when I use echo $e+1;
    it comes back as 1

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Find out exactly what curl is bringing back, and what type PHP interprets it to be before simply adding a 1 to it.

    use:
    PHP Code:
    var_dump($e); 

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Location
    EAST COAST
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://powercelltech.com/matt/a.php

    My
    PHP Code:
    var_dump($e); 
    runs on forever.

    And when it returns the value $e. I can not get any math out of it.

    right now $e echos 2.8. But that changes every so often. But when i try to add

    PHP Code:
    $e $f
    echo $f
    returns 2


    PHP Code:
    <?php

    include('simple_html_dom.php');
     
    $html file_get_html('https://btc-e.com/exchange/');



    foreach(
    $html->find('span#min_price') as $e)
      
      
        echo 
    $e->innertext '<br>';

    ?>

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    So, can you tell me whether you are getting 2.8 as a string or a float?

    That's why I asked you to var_dump() the variable ...

    http://php.net/manual/en/language.ty...e-juggling.php

  7. #7
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Location
    EAST COAST
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I copied the entire code above^.

    It pulls the current rate off btc-e for bitcoins in usd.

    the 2.8 changes.

    I have the cURL pulling the correct info, Just not sure how to alter it. I want to be able to take the current rate $e.

    and increase it by a percent.

  8. #8
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Location
    EAST COAST
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    So, can you tell me whether you are getting 2.8 as a string or a float?

    That's why I asked you to var_dump() the variable ...
    When I do the var_dump() it never ends....

    Almost 100% certain its a string. I did include my code above

  9. #9
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Maybe its the way you are adding the values up? This all works for me:

    PHP Code:
    $fl = (float) 2.8;

    var_dump($fl);

    $fl +=1;

    var_dump($fl);

    $st "2.8";

    var_dump($st);

    $st +=1;

    var_dump($st);

    // gives
    // float 2.8
    // float 3.8
    // string '2.8' (length=3)
    // float 3.8 

  10. #10
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Location
    EAST COAST
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    Maybe its the way you are adding the values up? This all works for me:
    I will try this, Since you seem to know your way around mind taking a look at the link and telling me how to pull out the information I need
    powercelltech.com/matt/a.php

    PHP Code:
    ["parent"]=>
          *
    RECURSION*
          [
    "_"]=>
          array(
    1) {
            [
    4]=>
            
    string(3"2.9"
          



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •