Php 从google通过表单获取图像不起作用?

Php 从google通过表单获取图像不起作用?,php,html,image,Php,Html,Image,我试着做了一个从,写了一个脚本,从谷歌获取图像,但它没有显示任何图像,也没有给出任何错误我该怎么办。 这是我的密码 <html> <head> <title>Images</title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="Post"> <table border="1"> &l

我试着做了一个从,写了一个脚本,从谷歌获取图像,但它没有显示任何图像,也没有给出任何错误我该怎么办。 这是我的密码

<html>
<head>
<title>Images</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="Post">
<table border="1">
<tr>
<td>Text:</td>
<td><input type="text" name="image" id="ImageType" value=""></td>
<td><input type="Submit" value="Click to Submit"></td>
</tr>
</table>
</form>
<br>

</body>
</html> 

<?php
include "simple_html_dom.php";
if(isset($_POST['submit'])) 
{ 
$search_query = $_POST['image'];


 // $search_query = "love";
 $search_query = urlencode( $search_query );
 $html = file_get_html( "https://www.google.com/search?q=$search_query& tbm=isch" );
 // $image_container = $html->find('div#rcnt', 0);
  $images = $html->find('img');
  $image_count = 10; //Enter the amount of images to be shown
  $i = 0;
  foreach($images as $image){
    if($i == $image_count) break;
    $i++;
    // DO with the image whatever you want here (the image element is '$image'):
    echo $image;
}
}
?>

图像
应该是

$html = file_get_html( "https://www.google.com/search?q=$search_query&tbm=isch" );
需要删除
search\u query&
tbm
之间的空格

编辑

<?php

if (isset($_POST['submit'])) {

    include "simple_html_dom.php";
    $search_query = $_POST['image'];
    $html = file_get_html("https://www.google.com/search?q=$search_query&tbm=isch");
    $images = $html->find('img');
    $image_count = 10; //Enter the amount of images to be shown
    $i = 0;
    foreach ($images as $image) {
        if ($i == $image_count)
            break;
        $i++;
        // DO with the image whatever you want here (the image element is '$image'):
        echo $image;
    }
}
?>

编辑-2 您应该为“提交”按钮指定名称属性,例如:

或使用:
if(isset($\u POST['image']){
而不是
if(isset($\u POST['submit'])){

buddy这不是问题,我尝试删除空格…这是一个工作代码。我可以用此代码获取图像。问题只在于额外的空格。这对我来说是工作,但我希望它在表单中作为用户类型工作。表单也在工作@ashishname属性在提交按钮中丢失,如EDIT-2所示。您没有收到ny错误,因为它从未进入if条件。我没有得到任何错误,正如我上面所说。。
<?php

if (isset($_POST['submit'])) {

    include "simple_html_dom.php";
    $search_query = $_POST['image'];
    $html = file_get_html("https://www.google.com/search?q=$search_query&tbm=isch");
    $images = $html->find('img');
    $image_count = 10; //Enter the amount of images to be shown
    $i = 0;
    foreach ($images as $image) {
        if ($i == $image_count)
            break;
        $i++;
        // DO with the image whatever you want here (the image element is '$image'):
        echo $image;
    }
}
?>