【メモ】simple_html_parserの使い方リンク
2015/04/18
[インストール~DOMオブジェクトの取得]
http://so-zou.jp/web-app/tech/programming/php/library/simplehtmldom/
メモ
タイトルの取得
findしたやつは配列集合なので、foreachで回すか[0]とかインデックスを指定しないといけない。。
$html= file_get_html($file_path);
$title = $html->find(“title”);
echo $title[0]->plaintext;
Tips (大事。見失わないように記録)
http://tips.recatnap.info/japanese_translation_manual_simple_html_dom_parser/
1 2 3 4 5 6 7 8 9 10 |
#HTMLからコンテンツを取得 echo $html->plaintext; #ラップする= 要素を別要素に追加する。 $e->outertext = "<div class=”wrap”>" . $e->outertext . "</div>"; #要素を削除、空データを代入 $e->outertext = ""; #要素の追加 $e->outertext = $e->outertext . "<div>foo</div>"; #要素の挿入 $e->outertext = "<div>foo</div>" . $e->outertext; |
関連記事
-
-
[php]期間指定で月一覧、日付一覧のデータ取得
123456789101112131415161718192021222324#日付けで取得(yyyy-mm-dd)function get_period_date (){$startDate = date('Y-m-d', strtotime('2018-01-06'));$endDate = date('Y-m-d', strtotime("2018-01-09"));$diff = (strtotime($endDate) - strtotime($startDate)) / ( 60 * 60 * 24);for($i = 0; $i <= $diff; $i++) {$period[] = date('Y-m-d', strtotime($startDate . '+' . $i . 'days'));}return $period;}#月(yyyy-mm)で取得function get_period_month(){$startDate = date('Y-m-d', strtotime('2017-01-06'));$endDate = date('Y-m-d', strtotime("2018-01-09"));$diff = (strtotime($endDate) - strtotime($startDate)) / ( 60 * 60 * 24 * 30);for($i = 0; $i <= $diff; $i++) {$period[] = date('Y-m', strtotime($startDate . '+' . $i . 'month'));}return $period;}
-
-
phpでcURLのhttps接続時エラー
“TCP connection reset by pe …
-
-
[php]mail()の送信元、エラー送信先設定(from, return-path)
ちょっと整理。 設定例 [crayon-62bad4150948b2651246 …
-
-
phpでhtmlからタグ、スクリプトの除去
スクレイピング中に需要が。 simple_html_parserの「innert …
-
-
MongoDBとPHP_リンクと個人的ポイントまとめ
=============================== リンク集 === …