How can I convert Csv to Json and recieve Post with Php?
I'm trying to convert Csv to Json with Php.
This is the Csv source: finance.sina.com. hk/cgi-bin/api/stock.cgi?action=stock&s=1
The value of 's', like example ablove: s=1, can be substituted with any number in order to recieve different stock's data.
And I've done this part (truboy.comeze. com/csv2json.php) :
$set = http_build_query( array( 'action' => 'stock', 's' => '1' ) );
$opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $set ) );
$url = "http://finance.sina.com.hk/cgi-bin/api/stock.cgi";
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
echo $result;
This code actually works. However, the value 's' is fixed with '1' and I want 's' to be changeable
Can I do sth. like 'posting data' eg csv2json.php?s=123 ?
Thanks guys!
How do you want it to be changed?
$feed = 123;
$set = http_build_query( array( 'action' => 'stock', 's' => $feed ) );
or something like
$set = http_build_query( array( 'action' => 'stock', 's' => (int)$_POST ) );
哎呀,我问了一个错误的问题,它应该'得到'不'后'无论如何,我找到我的解决方案
's' => (int)$_GET['s']
链接地址: http://www.djcxy.com/p/87302.html