1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Any PHP experts here? Need some PHP coding help.

Discussion in 'PHP' started by bertamus11, Aug 31, 2007.

  1. #1
    Hi there, can anyone make sense of what I'm supposed to put in here?

    Here's my original code:
    $fd = fopen (("http://quote.yahoo.com/d/quotes.csv?s=".$symbol."&f=sl1d1t1c1ohgv&e=.csv"), "r");
    $contents = fread ($fd, 200);
    fclose ($fd);
    $contents = str_replace ("\"", "", $contents);
    $contents = explode (",", $contents);

    echo '<style type="text/css">table { font-size: 12; } </style>';

    Here's what dreamhost says to use: wiki.dreamhost.com
    (http://wiki.dreamhost.com/Special:Search?search=fopen&go=Go)

    Anyone know? Thanks a bunch! I appreciate your time.
     
    bertamus11, Aug 31, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    What is your question? :confused:
     
    nico_swd, Aug 31, 2007 IP
  3. jakomo

    jakomo Well-Known Member

    Messages:
    4,262
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    138
    #3
    Yup, I dont understand what is your question :) Please explain us. Thanks
     
    jakomo, Aug 31, 2007 IP
  4. bertamus11

    bertamus11 Well-Known Member

    Messages:
    791
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    130
    #4
    Your both right...my post doesn't make any sense...sorry. :)
    I'll try again:

    First, I'm with Dreamhost and they don't allow the commands: fopen or fclose

    Here's the code in my php file:
    $fd = fopen (("http://quote.yahoo.com/d/quotes.csv?s=".$symbol."&f=sl1d1t1c1ohgv&e=.csv"), "r");
    $contents = fread ($fd, 200);
    fclose ($fd);
    $contents = str_replace ("\"", "", $contents);
    $contents = explode (",", $contents);

    echo '<style type="text/css">table { font-size: 12; } </style>';

    As I understand it, it's supposed to open up the url, grab the info for the stock symbol I entered on the search and display it.

    As Dreamhost doesn't allow the fopen and fclose commands, here is their suggestion on what to replace the original code with:

    Description
    cURL is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, FILE and LDAP. cURL supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos...), file transfer resume, proxy tunneling and other useful tricks.

    [edit] Examples
    [edit] Fetching a web page
    <?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://example.com/");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
    ?>
    [edit] Alternative for file_get_contents()
    Instead of:

    <?php
    $file_contents = file_get_contents('http://example.com/');

    // display file
    echo $file_contents;
    ?>
    Use this:

    <?php
    $ch = curl_init();
    $timeout = 5; // set to zero for no timeout
    curl_setopt ($ch, CURLOPT_URL, 'http://example.com');
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $file_contents = curl_exec($ch);
    curl_close($ch);

    // display file
    echo $file_contents;
    ?>
    Otherwise if you are getting some errors with the code above, use this:

    <?php
    $site_url = 'http://example.com';
    $ch = curl_init();
    $timeout = 5; // set to zero for no timeout
    curl_setopt ($ch, CURLOPT_URL, $site_url);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

    ob_start();
    curl_exec($ch);
    curl_close($ch);
    $file_contents = ob_get_contents();
    ob_end_clean();

    echo $file_contents;
    ?>
    *******************************************

    I cannot for the life of me figure this one out. What code should I put in place of my original code to make it display the info I want it to?

    *******************************************

    (A recent example of how I fixed a more simpler code that involved the fopen/etc.. commands:

    Instead of:
    $request ='http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid='.$api.'&query='.$keyword.'&output=php'.$parameter;
    $response = file_get_contents($request);

    I used this:
    $request ='http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid='.$api.'&query='.$keyword.'&output=php'.$parameter;
    $ch = curl_init();
    $timeout = 5; // set to zero for no timeout
    curl_setopt ($ch, CURLOPT_URL, $request);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $response = curl_exec($ch);
    curl_close($ch);
    )

    Any ideas? Your help would be appreciated. Thank you.
    (Hopefully I made sense this time)
     
    bertamus11, Sep 2, 2007 IP
  5. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Here's the combination of your code/curl code you should use:

    
    $url = "http://quote.yahoo.com/d/quotes.csv?s=".$symbol."&f=sl1d1t1c1ohgv&e=.csv";
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $contents = curl_exec($ch);
    curl_close($ch);
    $contents = str_replace ("\"", "", $contents);
    $contents = explode (",", $contents);
    
    PHP:
    Nico -- beat you to it ;)
     
    sea otter, Sep 2, 2007 IP
    bertamus11 likes this.
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Mwahaha. :p



    I wasn't going to reply now anyway. It's 5:26 am here and I didn't sleep yet. And there was way too much code for my tired eyes. :p
     
    nico_swd, Sep 2, 2007 IP
  7. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Only 11:30pm here. But by early morning I won't be posting any more code either :eek:
     
    sea otter, Sep 2, 2007 IP
  8. bertamus11

    bertamus11 Well-Known Member

    Messages:
    791
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    130
    #8
    Worked like a charm...

    Thank you very much sea_otter! I appreciate it.
     
    bertamus11, Sep 3, 2007 IP