如何用 php 中的变量替换 url 值?并在获取数组中获得动态结果?
How to Replace url value with variable in php? and get dynamic result in fetch array?
我想使数字“12345”和日期“02-07-2018”动态化以从文本框中获取其变量值..我还想在数组中获取结果(动态)..就像mysql_fetch_array(结果)..如何实现这一点??..任何帮助都将被分配
<?php
$json = '';
//url
$url = 'http://api.website.com/account/12345/date/02-07-2018/apikey/api_key/';
$content = file_get_contents($url);
$json = json_decode($content, true);
$acc_name = $json['account']['name'];
$acc_number = $json['account']['number'];
?>
<table width='100%' border=1>
<thead>
<tr bgcolor='#00ffcc'>
<th>account name</th>
<th>account number</th>
</tr>
</thead>
<tbody>
<td> <?php echo $acc_name; ?></td>
<td><?php echo $acc_number; ?></td>
希望这是您检索所需的内容。
$number = $_POST['number'] ;
$date = $_POST['date'] ; /* format if necessary */
$url = "http://api.website.com/account/$number/date/$date/apikey/api_key/";
要迭代,您可以使用
<?php
foreach( $json['account'] as $value ) {
$acc_name = $value['name'];
$acc_number = $value['number'];
?>
<td> <?php echo $acc_name; ?></td>
<td><?php echo $acc_number; ?></td>
<?php } ?>
我想使数字“12345”和日期“02-07-2018”动态化以从文本框中获取其变量值..我还想在数组中获取结果(动态)..就像mysql_fetch_array(结果)..如何实现这一点??..任何帮助都将被分配
<?php
$json = '';
//url
$url = 'http://api.website.com/account/12345/date/02-07-2018/apikey/api_key/';
$content = file_get_contents($url);
$json = json_decode($content, true);
$acc_name = $json['account']['name'];
$acc_number = $json['account']['number'];
?>
<table width='100%' border=1>
<thead>
<tr bgcolor='#00ffcc'>
<th>account name</th>
<th>account number</th>
</tr>
</thead>
<tbody>
<td> <?php echo $acc_name; ?></td>
<td><?php echo $acc_number; ?></td>
希望这是您检索所需的内容。
$number = $_POST['number'] ;
$date = $_POST['date'] ; /* format if necessary */
$url = "http://api.website.com/account/$number/date/$date/apikey/api_key/";
要迭代,您可以使用
<?php
foreach( $json['account'] as $value ) {
$acc_name = $value['name'];
$acc_number = $value['number'];
?>
<td> <?php echo $acc_name; ?></td>
<td><?php echo $acc_number; ?></td>
<?php } ?>