PHP Simple HTML DOM Parserを使ってサイトのタイトルなどを抽出できるものを制作しているのですが、URLを取得する方法がfile_get_htmlで指定してやる方法しか分からず、何か良い方法を良い方法を教えていただきたく質問させて頂きました。
テキキストボックスにURLを入力するとタイトルなどのメタデータが表示されるというものを制作したいです。
https://tech-unlimited.com/urltitle.html (URL to TITLE
URLからタイトルを取得します。複数一括処理もOK。)
具体的にはこのようなサイトを制作したいと考えております。
素人すぎて大変申し訳ございませんがアドバイスなどいただければ幸いです。
PHP
1<?php 2require_once 'simple_html_dom.php'; 3$html = new simple_html_dom(); 4$html = file_get_html("https://www.yahoo.co.jp/"); 5$title = $html->find("title", 0)->innertext; 6$description = $html->find("meta[name='description']", 0)->content; 7$keywords = $html->find("meta[name='keywords']", 0)->content; 8?> 9 10<input type="text" name="title" value="<?php echo htmlspecialchars($title, ENT_QUOTES); ?>"> 11<input type="text" name="description" value="<?php echo htmlspecialchars($description, ENT_QUOTES); ?>"> 12<input type="text" name="keywords" value="<?php echo htmlspecialchars($keywords, ENT_QUOTES); ?>">
回答1件
あなたの回答
tips
プレビュー