URL 抓取和显示输出 - 将输出作为$Array而不是值获取


URL Scraping and Displaying Output - Getting Output as $Array instead of value

我是PHP编码的新手,但熟悉该机制。我需要一个插件来从ASX(澳大利亚证券交易所)提取短代码中指定的任何公司代码的报价。

我已经完成了代码并在 Wordpress 上加载了插件,在前端而不是显示公司符号的价格,而是将输出作为"$Array"而不是值。

请看一看:

这是我的代码:

add_shortcode( 'asx-prices', 'asx_prices_shortcode' );
function asx_prices_shortcode( $atts ) {
extract( shortcode_atts( array(
    'symbol'        => '',
), $atts ) );
// Obtain Quote Info    
$data = file_get_contents( 'http://www.asx.com.au/asx/markets/priceLookup.do?by=asxCodes&asxCodes='. "{$symbol}" );
preg_match('/<td class="last">(.*)<'/td>/i', $data, $quote);
$output .= '<div class="asx_prices_symbol">Symbol: '. "{$symbol}" .'</div>';
$output .= '<div class="asx_prices_quote">Latest Price: $'. $quote .'</div>';
return $output;
}

这是输出:

Symbol: QVE
Latest Price: $Array
Symbol: QVEO
Latest Price: $Array

这是预期的结果:

Symbol: QVE
Latest Price: 0.985
Symbol: QVEO
Latest Price: 0.038

这是我关于Stack Overflow的第一篇文章,我想参与更多的PHP,这就是我今天开始的原因,将来我需要更多的专家帮助。谢谢你的时间。

preg_match返回一个数组。 很有可能$quote[0]会返回价格。

尝试执行print_r($quote);,看看所需的结果是否在数组中,以及它的位置。

preg_match将结果放在$quote变量中,创建一个数组。
您会在$quote[1]中找到自己的价值。

http://php.net/manual/en/function.preg-match.php