LoginSignup
0
0

More than 5 years have passed since last update.

phpqueryでh1~h6タグのテキストを取得する

Posted at

<?php
    require_once("./phpQuery-onefile.php");
    $html = file_get_contents("https://ja.wikipedia.org/wiki/%E3%82%A6%E3%82%A7%E3%83%96%E3%82%B9%E3%82%AF%E3%83%AC%E3%82%A4%E3%83%94%E3%83%B3%E3%82%B0");

    #ここでhtml全文を取得している
    $phpobj = phpQuery::newDocument($html);

    #hタグを取得
    $headers = $phpobj[":header"];

    #foreachで回して、pqで囲ってtext()するとhタグで囲まれた文字列を取得できる
    foreach ($headers as $header) {
      echo pq($header)->text()."<br>";
      echo "----------------<br>";
    }

  ?>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0