Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 没有带CURL的输出表单url_Php - Fatal编程技术网

Php 没有带CURL的输出表单url

Php 没有带CURL的输出表单url,php,Php,嗨,伙计们,我用我的代码从url获取文件数据我测试了curl函数,但我不知道我的代码有什么问题,因为我没有任何输出请有人告诉我如何解决这个问题我猜我在这一部分有问题: foreach($serverlist as $line) { $line = trim($line); 但我不知道如何解决这个问题: <?php function get_data($url) { $ch = curl_init(); $timeout = 5; curl_seto

嗨,伙计们,我用我的代码从url获取文件数据我测试了curl函数,但我不知道我的代码有什么问题,因为我没有任何输出请有人告诉我如何解决这个问题我猜我在这一部分有问题:

foreach($serverlist as $line) { 
$line = trim($line); 
但我不知道如何解决这个问题:

<?php

function get_data($url) 
{
    $ch = curl_init();
    $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $data = curl_exec($ch);
        curl_close($ch);
    return $data;
}

$serverlist = get_data("http://185.49.84.109/iw5msl/serverinfo.txt");
$file_headers = @get_headers($serverlist);

if(($file_headers[0] == 'HTTP/1.0 404 Not Found') || ($file_headers[0] == 'HTTP/1.0 302 Found' && $file_headers[7] == 'HTTP/1.0 404 Not Found'))
{ 
    echo "The server list is currently being changed due to some upgrades and therefore not available. Sorry for any inconvenience.";
} else {

$odd = false;
foreach($serverlist as $line) { 
$line = trim($line); 
list($name,$ip,$players,$map,$type,$mod,$country) = explode("|!|!|", $line . "|!|!|");
$ixp = explode(":", $ip);
if(in_array($ixp[0], file("data/servers.banlist")) || in_array($ip, file("data/servers.banlist"))) continue;
$type = parse_gametype($type);
$map = @$_MAPS["mw3"][$map];
if(strstr($map, "<") > -1) $map = "Server by idiot.";
list($players,$maxplayers) = explode("/", $players);
$country = "<span style=\"display:none\">$country</span><img alt=\"$country\" title=\"$country\" src=\"".parse_flag($country)."\" />";
?>
<tr style="height: 50px">
                            <td style="text-align:left"><span style="display: none"><?php echo preg_replace("/[^a-zA-Z0-9\s]/", "", strip_tags($name)); ?></span>
                                <span style="font-size: 1.5em; font-family: 'Play', 'OCR A Extended'"><?php echo $name; ?></span><br />
                                <span style="font-size: 1.3em"><?php echo $ip; ?></span>
                            </td>
                            <td style="text-align: right; font-size: 1.5em"><?php echo $players; ?></td>
                            <td style="font-size: 1.5em">/</td>
                            <td style="text-align: left; font-size: 1.5em; width: 50px"><?php echo $maxplayers; ?></td>
                            <td style="font-family: Electrolize; letter-spacing: 1px; font-size: 1.4em; text-align:right; display: color:white;background-size:100%;background-position:center center;background-image:url(<?php echo $map_thumb; ?>)">
                                <div class="blackgradient gradient"><?php echo $map; ?></div>
                            </td>
                            <td><?php echo $type; ?></td>
                            <!--<td><?php echo $mod; ?></td>-->
                            <td><?php echo $country; ?></td>
                        </tr>
<?php $odd = !$odd; ?>
<?php } ?>
                    </tbody></table>
<?php } ?>


/ 尝试添加

$serverlist=explode("\n", $serverlist);
在FOREACH线之前

Thx,它应该是
“\n”

对于尾部的空行,使用FOREACH附近的空行:

$serverlist=explode("\n", $serverlist); //ADDED
$odd = false;
foreach($serverlist as $line) { 
$line = trim($line); 
if(empty($line))continue; //ADDED

curl不返回数组。它以字符串形式返回响应。你不能用foreach()来表示字符串。对吗?如何修复它
'
-带引号的字符串不支持
\n
-类型的转义序列。您需要使用
“\n”
,这将是一个换行符,但我的输出中有一个额外的行如何修复它?检查foreach中的$line是否为空,如果为空,继续操作。我添加了如果($line==空)继续;但是销毁一切:请你给我正确的代码谢谢
($line==empty)
在PHP中似乎不正确。在我更新时使用
空($line)