laravel 5.7中的返回变量的问题

时间:2018-11-20 19:58:30

标签: php laravel laravel-5

我使用Laravel 5.7。程序运行时可以看到网站,但完成后(返回功能)不会在页面中显示所有网站。我认为返回情节的问题,但我无法解决。

功能

public function sls(Request $request){
    $ip = $request->input('ip');
    $cnt=1;
    $count=0;
    ini_set('max_execution_time', 600);
    $nextpage=true;
    while($nextpage==true){
        if($cnt==1)
            $url="https://www.bing.com/search?q=ip%3A".$ip."&qs=n&form=QBRE&pq=ip%3A".$ip."&sc=0-0&sp=-1&sk=";
        else
            $url="https://www.bing.com/search?q=ip%3a".$ip."&qs=n&sp=-1&pq=ip%3a".$ip."&sc=0-15&sk=&cvid=75D6BFCE5DF344E083DF2C10D5B735E9&first=".$cnt."&FORM=PERE";

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        $result=curl_exec($ch);
        $myPattern = "#<cite>(.*?)</cite>#" ;

        if(preg_match_all($myPattern,$result,$find)){
            $urls = preg_replace("/<\/?strong>/","",$find[1]);
            $keys = array_filter($urls);
            $html = '<ul>';
            foreach($keys as $value){
                $count += 1;
                $html .= '<li> '.$count.'.'.$value.' </li>';
            }
            $html .= '</ul>';
            echo $html;
        }
        if(preg_match('/class="sb_pagN sb_pagN_bp b_widePag sb_bp "/',$result))
            $cnt+=40;
        else
            $nextpage=false;
    }
    return back()->with('list', $html);

表格

<form action = "" method = "post">
<input type = "hidden" name = "_token" value = "<?php echo csrf_token() ?>">

<table>
    <tr>
        <td>Server list site: </td>
        <td><input type="text"  name="ip" /></td>
    </tr>
</table>

{!! session('list')!!}

2 个答案:

答案 0 :(得分:0)

您将旧页面写满了最后一页。

进行以下更改:

$html = '';

在上面添加上述内容。

$html .= '<ul>';

更改为上面的行。

这将允许所有网站都包含在$ html变量中。

答案 1 :(得分:0)

  

程序运行时可见网站,但完成后(返回功能)未在页面中显示所有网站。

我认为您需要从控制器echo $html;方法中删除sls()行:

if(preg_match_all($myPattern,$result,$find)){
    $urls = preg_replace("/<\/?strong>/","",$find[1]);
    $keys = array_filter($urls);
    $html = '<ul>';
    foreach($keys as $value){
        $count += 1;
        $html .= '<li> '.$count.'.'.$value.' </li>';
    }
    $html .= '</ul>';
    echo $html; // <------- Remove this line.
}