0

Web サイト 1 でこの設定を行っている場合:

<div class="awesomeContent">
    <div>
        Information goes here...
    </div>
    <div>
        Information goes here...
    </div>
    <div>
        Information goes here...
    </div>
</div>

次に、これをWebサイト2で使用する場合:

<?php
$data = file_get_contents('http://website.com/hello);
preg_match_all ("/<div class=\"awesomeContent\">([^`]*?)<\/div>/", $data, $matches);
print_r($matches[0]);

投稿したい:

<div class="awesomeContent">
    <div>
        Information goes here...
    </div>
    <div>
        Information goes here...
    </div>
    <div>
        Information goes here...
    </div>
</div>

しかし、私が得るのは

<div class="awesomeContent">
    <div>
        Information goes here...
    </div>

どうすればこれを改善できますか?

4

1 に答える 1

0

ここでは、次のような dom 解析を使用することをお勧めします

$parsedHtml = simplexml_load_string($data);
print_r($parsedHtml)`

しかし、それでも問題の解決策は交換することです

 "/<div class=\"awesomeContent\">([^`]*?)<\/div>/"

  "/<div class=\"awesomeContent\">([^`]*)<\/div>/"

最初のdivにのみあるパターンでクラスを使用しているため

于 2013-03-26T04:22:29.723 に答える