LoginSignup
13
12

More than 5 years have passed since last update.

PHP Simple HTML DOM Parserで文字化けするときの対処法

Posted at

Simple HTML DOMで、外部のファイルを扱う場合、

// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');

と書くことが多い。

でも日本語サイトの場合は、文字化けする可能性が高いので、

mb_language('Japanese');

$source = file_get_contents('http://www.google.com/');
$source = mb_convert_encoding($source, 'utf8', 'auto');

$dom = str_get_html($source);

とやった方がいい。

参考

PHP Simple HTML DOM Parser
http://simplehtmldom.sourceforge.net/

Simple HTML DOM Parserのサンプル
http://tips.recatnap.info/sample_simple_html_dom_parser/

13
12
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
13
12