如何限制simplexml_load_file()的结果

时间:2019-06-08 13:42:11

标签: php

我的代码工作正常,但是结果是无限的。如何限制结果?

<form action="<?php  $_SERVER['PHP_SELF']; ?>" method="post">
            Keyword: <input type="text" name="keyword"  required>
            <input type="submit">
        </form>

<?php

if (isset($_POST["keyword"]) && $_POST['keyword'] !== "") {    
$alphas1 = range('A', 'Z');    
$alphas2 = range('A', 'Z');    
$keyword = $_POST['keyword'];    
foreach ($alphas1 as $a1) {        foreach ($alphas2 as $a2) {            
$xml = simplexml_load_file(utf8_encode("http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=$keyword.' '.$a1.$a2"));            
foreach ($xml->children() as $child) {                               
foreach ($child->suggestion->attributes() as $dta) {                                        

echo $dta.", ";                                   
 }            }                    }    }} ?>

0 个答案:

没有答案