Simple Html Dom Parser



  • No text swapping at h3 has tried several options, as I understood the problem in the index of the element

        <div class="photo">
          <div class="img">          
            <div class="p10">
              <a href="/upload/1.png"/></a></div>
                <h3>текст</h3>
            </div>
          </div>
        </div>
    

    First option

    include_once ('components/simple_html_dom.php');
    $html = new simple_html_dom();
    $html = file_get_html('parser.html');
    $tovar = $html->find('photo img ') as $tovar_img;
    $tovar_img = $tovar->find('div.img p10 ', 0) as $tovar_p10;
    $tovar_p10 = $tovar_img->find('div.p10 h3 ', 0) as $tovar_name;
    echo $tovar_name;
    

    second option

    include_once ('components/simple_html_dom.php');
    $html = new simple_html_dom();
    $html = file_get_html('parser.html');
    $tovar = $html->find('div.photo', 0) -> find('div.img') -> find('div.p10') -> find('div.h3') as $tovar_name;
    echo $tovar_name;
    

    third option

    include_once ('components/simple_html_dom.php');
    $html = new simple_html_dom();
    $html = file_get_html('parser.html'); 
    if(count($html->find('photo'))){
       foreach($html->find('div.photo div.img div.p10 div.h3') as $h3){
         echo $h3->plaintext.'<br>';
       }
    }
    


  • You're confused. str_get_html() c file_get_html()

    We need to write:

    $html = file_get_html('parser.html'); 
    

    Then you don't have to.

    $html = new simple_html_dom();
    

    or:

    $html = new simple_html_dom();
    $html->load_file('parser.html');
    

    Completed

    Also to find the element you need to write is enough:

    $tovar_name = $html->find('.photo .img h3', 0);
    

    See also:

    http://simplehtmldom.sourceforge.net/manual.htm#section_create




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2