954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Using PHP to echo into URL

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

gilgil2
Junior Poster in Training
68 posts since Aug 2011
Reputation Points: 10
Solved Threads: 1
 

try

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


or

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


it
short tags sometimes cause problems

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

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,':',$spos)+3;
$spos = strpos($wrss,'',$spos);
$epos = strpos($wrss,'

gilgil2
Junior Poster in Training
68 posts since Aug 2011
Reputation Points: 10
Solved Threads: 1
 

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

$data = processStockSite('http://finance.yahoo.com/q?s='.$epic.'.l');
almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

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

gilgil2
Junior Poster in Training
68 posts since Aug 2011
Reputation Points: 10
Solved Threads: 1
 
almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: