即時通訊工具在SEMRUSH api上的項目和結果來到$ field1; field2如此分隔;PHP陣列和API的問題
當前結果我得到了這樣5 reslts彼此相鄰基於其列,不過,我需要第二陣列僅
if (isset($_POST['search_term'])) {
$kwtext1 = str_replace(" ", '+', ($_POST['search_term']));
$kwtext = str_replace("\r", '', trim($kwtext1));
$kwdata = array();
$kwlines = explode("\n", $kwtext);
$db = "us";
$limit = "10";
}
foreach ($kwlines as $kw) {
usleep(100);
$u = 'http://' . $db . '.api.semrush.com/?action=report&type=phrase_this&phrase=' . $kw . '&key=' . $key . '&display_limit=' . $limit . '&display_offset=0&export=api&export_columns=Ph,Nq,Cp,Co,Nr';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $u);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$answer = curl_exec ($ch);
$kwdata = explode ("\n", trim ($answer));
$kwfields = explode (";", array_shift ($kwdata));
if (count ($kwdata) > 0)
{
?>
<table class="output">
<tr><th>Domain 1</th>
<?php $csv_output .= ' ' . ", " . 'Domain' . ", ";?>
<?
foreach ($kwfields as $field)
{
?>
<th><?= $field; ?></th>
<?php $csv_output .= $field . ", ";?>
<?
}
?>
</tr>
<?
foreach ($kwdata as $dataline)
{
$values = explode (";", $dataline, count ($kwfields));
?>
<tr><td><? echo $kw ?></td>
<?php $csv_output .= $kw . ", ";?>
<?
foreach ($values as $value)
{
?>
<td><?= $value; ?></td>
<?php $csv_output .= $value . ", ";?>
<?
}
?>
</tr>
<?
}
?>
</table>
<?
}
else
{
?>
No data found for your request
<?
}
}
?>
你的問題到底是什麼? – ohmusama