就是做一个提交表单,把多个网址提交给php处理,判断这个网址的内容里面是否包涵一个特定的句子.并把这个网址和数据库里的网址做一下比对,看数据库是否存在这个地址.两个都符合的弹出提示通过,不符合的提示失败.
请问可以帮忙下吗

解决方案 »

  1.   

    你可以把你数据中的网址放入一个数组中。假设为$arr
    if(strpos(file_get_contents($_POST['url']),'特定的句子') !==false && in_array($_POST['url'],$arr)){
               echo '通过';   
    }else{
               echo "不通过";
    }
      

  2.   

    <input type="text" name="url[]">
    <input type="text" name="url[]">
    <input type="text" name="url[]">//可以以数组形式提交。php端循环就是了。
    $urls=$_POST['url'];
    for($i=0;$i<count($urls;$i++)){
    if(strpos(file_get_contents($urls[$i]),'特定的句子') !==false && in_array($urls[$i],$arr)){ 
       echo "$i通过<br>"; 
    }else{ 
         echo "$i不通过<br>"; 
    }
    }
    数据库端: 
    //..............数据库连接省略....
    $result=mysql_query("select url from table") or die(mysql_error());
    while($row=mysql_fetch_assoc($result)){
             $arr[]=$row['url'];  // 构建url数组
    }
      

  3.   

    <?php
    $urls=$_POST['url'];
    for($i=0;$i<count($urls;$i++)){
    if(strpos(file_get_contents($urls[$i]),'特定的句子') !==false && in_array($urls[$i],$arr)){ 
       echo "$i通过<br>"; 
    }else{ 
         echo "$i不通过<br>"; 
    }
    }
    ?>
    <form action="yz.php?url=url[]" method="post">
    <input type="text" name="url[]"><br />
    <input type="text" name="url[]"><br />
    <input type="text" name="url[]"><br />
    <input type="button" />
    </form>
    这么写的,提示第三行错误.另外怎么把数据库的验证也放进去?是想数据库内容和特定句子内容同时验证,都通过的提示通过,有不通过的提示不通过
      

  4.   

    for($i=0; $i<count($urls); $i++){   //这样,刚才手误写错了。把 #4 数据那一段放在for循环前面就行了。
      

  5.   

    提示:Notice: Undefined index: url in G:\wampserver\wamp\www\yz.php on line 2
    下面的html代码不知道是不是写错了
      

  6.   

    有<input type="text" name="url[]">?print_r($_POST); 看有没数据
      

  7.   

    <form action="yz.php" method="post">
    <input type="text" name="url[]"><br />
    <input type="text" name="url[]"><br />
    <input type="text" name="url[]"><br />
    <input type="submit" />
    </form>
      

  8.   

    提示是下面这个,另外刚开始的地方还有undefined怎么去掉呢?
    Warning: file_get_contents(baidu.com) [function.file-get-contents]: failed to open stream: No such file or directory in G:\wampserver\wamp\www\yz.php on line 4Notice: Undefined variable: i不通过 in G:\wampserver\wamp\www\yz.php on line 7
      

  9.   

    给url前面加上:http://www.  第七行是哪行?
      

  10.   

    echo "$i不通过<br>"; 
    }
      

  11.   

    <?php
    $urls=$_POST['url'];
    print_r($urls);$arr = array('http://baidu.com'); // 假设数据库地址
    for($i=0;$i<count($urls);$i++){
    $c = file_get_contents($urls[$i]);
    if(in_array($urls[$i],$arr) && strpos($c,'baidu') !==false)
      echo "{$urls[$i]}通过<br>";  
    else
      echo "{$urls[$i]}不通过<br>";  
    }
    ?>
    <form action="Noname11.php" method="post">
    <input type="text" name="url[]" value="http://baidu.com"><br />
    <input type="text" name="url[]" value="http://g.cn"><br />
    <input type="text" name="url[]"><br />
    <input type="submit" />
    </form>
      

  12.   

    Array ( [0] => http://baidu.com [1] => http://g.cn [2] => ) http://baidu.com通过
    http://g.cn不通过Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in G:\wampserver\wamp\www\yz2.php on line 7
    不通过
      

  13.   

    这个是整个的代码,不过好像数据库的判断没效果,另外提示
    Notice: Undefined index: url in G:\wampserver\wamp\www\yz2.php on line 9
    http://baidu.com不通过
    http://g.cn不通过Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in G:\wampserver\wamp\www\yz2.php on line 12
    不通过
    <?php
    $urls=$_POST['url'];
    print_r($urls);
    mysql_connect("localhost", "root", "") or
            die("Could not connect: " . mysql_error());
        mysql_select_db("dedecmsv57utf8sp1");
    $result=mysql_query("select title FROM dede_archives") or die(mysql_error());
    while($row=mysql_fetch_assoc($result)){
             $arr[]=$row['url'];  // 构建url数组
    }
    for($i=0;$i<count($urls);$i++){
    $c = file_get_contents($urls[$i]);
    if(in_array($urls[$i],$arr) && strpos($c,'baidu') !==false)
    echo "{$urls[$i]}通过<br>";   
    else
    echo "{$urls[$i]}不通过<br>";   
    }
    ?>
    <form action="yz2.php" method="post">
    <input type="text" name="url[]" value="http://baidu.com"><br />
    <input type="text" name="url[]" value="http://g.cn"><br />
    <input type="text" name="url[]"><br />
    <input type="submit" />
    </form>
     
      

  14.   

    你如何知道数据库的判断没效果的? print_r($arr);  //你的数组里面是什么东西<input type="submit" />
     ==》
    <input type="submit" name="submit" value="提交" />$c = file_get_contents($urls[$i]);前面加上: if(empry($urls[$i])) continue;最外层加一句: if(isset($_POST['submit'])){
                  你的php代码......................
       }
      

  15.   

    楼主你应该自己动手解决问题了。
    上面都贴了这么多代码了,jordan102也给你说了这么多,
    有点基础稍微改下就没问题了。
    不要到头来只是死问,要加强自己的解决问题能力。