Hi

I am trying to include the code xta into this below url, it works with other parts on the page, but there is something to do with this URL that appears to stop it working. Would anyone be able to tell me why xta does not get inserted where the <?=$code?> is?

<?php
$code = "xta";
?>

$data = processStockSite('http://finance.yahoo.com/q?s=<?=$code?>.l');

Thanks in advance

Recommended Answers

All 5 Replies

Thanks for the quick reply

I have tried the things you suggested but nome of them work for me. I am not sure what I am doing wrong. I have posted some more code, maybe you can spot the problem? I would be very grateful.

I have changed it a little bit so that the echo is the file name, but it is essentially the same. The echo works elsewhere, and in other URLs but still not this one.

<?php


function getStockSite($stockLink){

   if ($fp = fopen($stockLink, 'r')) {
      $content = '';

      while ($line = fread($fp, 1024)) {
         $content .= $line;
      }
   }

   return $content;  
}

function processStockSite($wurl){

    $wrss = getStockSite($wurl);
    $name  = '-';
    $price = '';
    $diff  = '';

    if (strlen($wrss)>100){
        $spos = 0;

        // Get text
        $spos = strpos($wrss,'</span>:',$spos)+3;
        $spos = strpos($wrss,'<big>',$spos);
        $epos = strpos($wrss,'</div><h1>',$spos);
        if ($epos>$spos){
           $text = substr($wrss,$spos,$epos-$spos);
        } else {
           $text = '-';
        }

        $spos = $epos + 10;
        // Get company name
        $epos = strpos($wrss,'<',$spos);
        if ($epos>$spos){
            $name = substr($wrss,$spos,$epos-$spos);
        } 


        // Get actual price
        $spos = strpos($wrss,'yfs_l10')+strlen('yfs_l10');
        $spos = strpos($wrss,'>',$spos)+1;
        $epos = strpos($wrss,'<',$spos);
        if ($epos>$spos){
            $price = substr($wrss,$spos,$epos-$spos);
        } else {
            $price = '-';
        }

        // Get direction
        $spos = strpos($wrss,'alt',$epos)+strlen('alt')+2;
        $epos = strpos($wrss,'"',$spos);
        if ($epos>$spos){
            $dir = strtolower(substr($wrss,$spos,$epos-$spos));
        } 

        // Get difference
        $spos = strpos($wrss,'>',$epos+3)+1;
        $epos = strpos($wrss,'<',$spos);
        if ($epos>$spos){
            $diff = substr($wrss,$spos,$epos-$spos);
        } 

    }

    $result['name']  = $name;
    $result['value'] = $price;
    $result['diff']  = $diff;
    $result['direction'] = $dir;
    $result['text']  = $text;

    return $result;

}

$currentFile = $_SERVER["PHP_SELF"];
$parts = split('[./]', $currentFile);
$epic = $parts[count($parts) - 2]; 

$data = processStockSite('c:\q.htm');
$data = processStockSite('http://finance.yahoo.com/q?s=echo $epic.l'); 

?>

This displays the following:

Warning: fopen(http://finance.yahoo.com/q?s=echo $epic.l) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /hermes/web11b/b146/moo.3finking/company/zox.php on line 16

I have missed out 4 lines, so it is actually on line 12.

I have highlighted where I think the problem is, but I may be (and probably am) completely wrong.

Thanks for your help.

That worked! Thank you so much, you have saved me a lot of time!

;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.