从URL获取数据时出现问题。 PHP

时间:2016-02-29 04:06:51

标签: php

我有以下代码。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="8dp" >

<!-- LEFT AREA START (VISIBLE) -->
<LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_marginRight="5dp"
    android:layout_weight="1"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >


        <ImageView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2"
            android:gravity="center"
            android:src="@drawable/ic_launcher" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="center"
            />

    </LinearLayout>
</LinearLayout>
<!-- LEFT AREA END -->


<!-- CENTER AREA (VISIBLE) -->
<LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="2"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            android:layout_weight="2"
            />

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            android:layout_weight="2"
            />
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            android:layout_weight="1"
            />

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            android:layout_weight="1"
            />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            android:layout_weight="1"
            />

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            android:layout_weight="1"
            />
    </LinearLayout>

</LinearLayout>
<!-- CENTER AREA END -->


<!-- RIGHT AREA START (INVISIBLE) -->
    <!-- I don't know what to do -->
<!-- RIGHT AREA END -->

如果我们看到下面的代码产生10个锚点

<?php error_reporting(0); $url = 'https://www.inmateaid.com/prison-search/all?&page=1'; $output = file_get_contents($url); $doc = new DOMDocument(); $doc->loadHTML($output); $selector = new DOMXPath($doc); $anchors = $selector->query("/html/body//div[@class='media']//div/h4//a"); foreach($anchors as $a) { $output = file_get_contents($a->getAttribute("href")); echo 'hi'; } ?>

那么应该怎样打印10次?但它只打印了3次。

当我在for循环中注释该行时,它会被打印10次。

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

那是由于max_execution_time = 30。我增加了时间,问题得到解决。

相关问题