> function get_file($url)
> {
>    return implode('', file($url));
> }

> Have fun with it ;)

It works great!
But now I'm having a quirky problem with strings.

I'm stripping stock prices from globeinvestor.com, and everything
is going well except for this quirk.  I pull down the web page
with your code snippet, and first I parse out the Company Name
and time of last trade before caling "strip_tags" on the string
to strip out all the HTML tags.  The resulting string I'm left
with you can see at :

http://www.alanmckay.com/phplib/stocks.php

The last 3 lines are my parsed out time of last trade,
company name, and finally my attempt to parse out last trade price.
You can see it appears as "Last: C$ 7.010 " in the string
so I use the following ereg call do do it :

if ( $retcode = ereg( 'Last: (C|US)\$ [0-9]+\.[0-9]{3} ', $myStr, $match) )

And it wasn't working so I kept tweaking and tweaking and still
nothing.  Finally I decided to see if it was perhaps something
wrong with the string that I'm passing into my function to find
the last trade price.  So instead of using the dynamic data I pulled
down and passed through "strip_tags", I manually cut out the following
substring and assigned it directly to my variable before passing
it into my function :

$noTags = "EST Enter New Symbol   Last: C$ 7.010 Net Change:  C$ 0.230 % 
Change:  ";

It turns out that my function was working great!  I managed to parse
the price out of that string no problem at all.  There appears to be
some kind of problem with the string that I'm passing into my function.
But what?  This is especially strange because I had no such problems
with the original string before handing it over to "strip_tags".
Also, I tried echoing the string first thing inside the function and
it looks just like it does when I echoed it before calling the function.
When I took the pre-stripped string and echoed it, I of course got
and exact duplicate of the webpage from globeinvestor.com.

Does anyone have any tips on what could be up here?

My functin is very simple :

function StockLastTradePrice( $myStr )
{
// [Last: C$ 7.010 ]
         if ( $retcode = ereg( 'Last: (C|US)\$ [0-9]+\.[0-9]{3} ', 
$myStr, $match) )
                 return  substr( substr( $match[0], 6 ), 0, -1);
         else
                 return "";
}


cheers,
-Alan




-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to