首页 > 解决方案 > laravel 5.7中返回变量的问题

问题描述

我使用 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>

{!!会话(“列表”)!!}

标签: phplaravellaravel-5

解决方案


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

我认为您需要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.
}

推荐阅读