Jump to content

Echo Problem After Site Migration


tarleton

Recommended Posts

This script used to work fine on my local host however when treansfed to a live site i get the following output:

 

echo $data['text']; ?>  

 

Here is code:

 

<?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;
    
}


// Get stock data
//$data = processStockSite('c:\q.htm'); // Google
$data = processStockSite('http://finance.yahoo.com/q?s=TLS.AX'); // Google
//$data = processStockSite('http://finance.yahoo.com/q?s=MSFT'); // Microsoft
//$data = processStockSite('http://finance.yahoo.com/q?s=AAPL'); // Apple
//$data = processStockSite('http://finance.yahoo.com/q?s=GE'); // GE
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>Micro Stock</title>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="main">
    <div id="caption"> </div>
     <div id ="icon2"></div>
      <div id="result">
<?php 
         echo $data['text'];
         //echo $data['value'].' ';
         //if ($data['direction'] == 'up') echo '<span class="up"> +'.$data['diff'].'</span>';
         //else echo '<span class="down"> -'.$data['diff'].'</span>'; ?>
      </div>

</div>
</body>
?>

 

 

 

Help appreciated.

Link to comment
Share on other sites

Is that your exact code? The most common cause of PHP code appearing on the client side is the developer using short_open_tags (<? rather than <?php) and them not being enabled on the server. I can't personally think of any other configuration setting that could cause only part of your PHP to appear on screen.

Link to comment
Share on other sites

When you do a "view source" of the page in your browser, what do you get? Specifically, is the raw php code at the top of the page visible or does the page start with the doctype output?

 

Is the code in a file with a .php extension?

 

Does any other .php page with some php code on it work as expected?

 

I'm running the code in conjunction with a CMS called MODX
Define "in conjunction with"? Is the posted code an independent .php page that you are browsing to directly or is it some template or other content that the CMS is reading in?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.