donte1234567 2014-12-11 15:20
浏览 21

使用simple_html_dom从文本文件中查找多个字符串,仅显示最后一个

I have a text file with 3 sentences from a URL, two sentences are present. No matter what i do, this code always just shows the last variable from the textfile. It looks exactly as what we need, but we need it forevery word/sentence.

Played for hours, cannot get it to work. Who can point me in the right direction?

[php]

$url = "http://www.".$_GET['u']; //"example.com/";
$lines = file("all_claims.txt");

include_once('simple_html_dom.php');

function scraping_for_text($iUrl,$iText)
{
    // create HTML DOM
    $html = file_get_html($iUrl);

    // get text elements
    $aObj = $html->find('text');
    foreach ($aObj as $key=>$seString)
    {
      $plaintext = $seString->plaintext;
      if (stripos($plaintext,$iText) !== FALSE)
      {
         echo "<b>".$iText."</b><br />";
         echo $key.": text=".$plaintext."<br />"
              ."--- parent tag=".$seString->parent()->tag."<br />";
      }

    }

    // clean up memory
    $html->clear();
    unset($html);

    return;
}

ini_set('user_agent', 'My-Application/2.5');

foreach($lines as $line)
{
    echo $line."<br />";
    scraping_for_text($url,$line);
}

[/php]

I would really appreciate the help.

KK.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化