SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Read from External file and Send The Query to Server

    Hi,
    I am working on a finance project and need to get quotes from Yahoo Finance based on the Symbols available in a external file... say symbols.php

    It has symbols in the following fashion
    Code:
    Microsoft
    Google
    Apple
    Wallmart
    .
    .
    .
    Bell
    When I include this symbols file in my parsing script I need to send query as
    PHP Code:
    http://yahoo.com/?s=<symbol1,symbol2... > 
    My requirement is to append the list from symbols.php make it in a csv format like Google,Apple.Wallmart,Bell

    so the query constructs as
    HTML Code:
    [CODE]http://yahoo.com/?s=Google,Apple.Wallmart,Bell[/CODE]
    How do I perform this required task?
    http://kkonline.org - Inspiring Life...

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Code PHP:
    <?php
    $symbols = file('path/to/symbols.txt');                //load symbols
    $symbols = array_filter($symbols, null);                //remove empty lines
    $symbols = array_map('urlencode', $symbols);            //make safe for url
     
     
    $url = 'http://yahoo.com/?s=' . implode(',', $symbols);    //create url
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AnthonySterling View Post
    Code PHP:
    <?php
    $symbols = file('path/to/symbols.txt');                //load symbols
    $symbols = array_filter($symbols, null);                //remove empty lines
    $symbols = array_map('urlencode', $symbols);            //make safe for url
     
     
    $url = 'http://yahoo.com/?s=' . implode(',', $symbols);    //create url

    Thanks for your suggestions, I tried this but get an error basically when I print $symbols[0] etc then only the data is visible; if I print echo $symbols no data is visible and I get warning like Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in /home/.... and
    Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/...

    $symbols = file('/home/mysite/public_html/stock/symbols.txt'); //load symbols
    echo $symbols; >> No data visible only Array is printed
    $symbols = array_filter($symbols, null); //remove empty lines
    $symbols = array_map('urlencode', $symbols);
    http://kkonline.org - Inspiring Life...

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Remove the null.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    PS: You cant echo an array. print_r or var_dump it instead.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


Tags for this Thread

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
  •