Skip to content

Instantly share code, notes, and snippets.

View narita1980's full-sized avatar
🎯
Focusing

narita1980 narita1980

🎯
Focusing
View GitHub Profile
package main
import (
"fmt"
"strconv"
"strings"
)
func main() {
for i := 1; i <= 100; i++ {
@narita1980
narita1980 / gist:5307201
Last active December 15, 2015 18:58
[PHP]str_get_htmlの説明(PHP Simple HTML DOM Parser)
/**
* get html dom from string
*
* @param string $str html domを取得する対象の文字列
*
* @param bool $lowercase Force the selectors to all be lowercase.
*
* @param bool $forceTagsClosed Forcing tags to be closed implies that we don't trust the html,
* but it can lead to parsing errors if we SHOULD trust the html.
*
@narita1980
narita1980 / gist:5307141
Last active December 15, 2015 18:49
元の状態を維持したまま解析をする(str_get_html)
<?php
require_once('classes/simple_html_dom.php');
$str = <<<EOT
<html>
<head></head>
<body>This is a test.</body>
</html>
EOT;
@narita1980
narita1980 / gist:5307085
Created April 4, 2013 01:54
元の状態を維持したまま解析をする(file_get_html)
<?php
require_once('simple_html_dom.php');
$url = "http://google.co.jp";
$html = file_get_html($url, false, null, 1, -1, true, true, DEFAULT_TARGET_CHARSET, false);
echo $html;
?>
@narita1980
narita1980 / gist:5298911
Created April 3, 2013 06:33
[備忘録]preg_match_allの使用例
<?php
preg_match_all('/hoge/', 'This is a test.', $matches);
foreach($matches as $val) {
echo "result: " . $val[0] . "\n";
}
/*****
Output:
result:
@narita1980
narita1980 / gist:5298881
Last active December 15, 2015 17:49
preg_match_allを使う際の注意点 ※同じ不一致の場合でも戻り値が異なる
<?php
preg_match_all('/hoge/', 'This is a test.', $matches);
var_dump($matches);
preg_match_all('/hoge/', 'This is a test.', $matches, PREG_SET_ORDER);
var_dump($matches);
/*****
Output:
Warning: strtotime(): It is not safe to rely on the system's timezone settings.
You are *required* to use the date.timezone setting or the date_default_timezone_set() function.
In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.
We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.
in /xxxx.php on line 52
@narita1980
narita1980 / gist:5150001
Last active December 14, 2015 21:19
file_get_contentsでproxy設定が必要なときのエラーメッセージ
Warning: file_get_contents(http://xxx.co.jp/xxx.jpg):
failed to open stream: operation failed in /xxxx.php on line 66
@narita1980
narita1980 / gist:5149985
Created March 13, 2013 07:29
proxy経由でfile_get_contentsを利用する方法 [参考サイト] http://www.php.net/manual/ja/function.file-get-contents.php#58758
<?php
$proxy = array(
'http' => array(
'proxy' => 'tcp://127.0.0.1:8080',
'request_fulluri' => True,
),
);
$context = stream_context_create($proxy);
@narita1980
narita1980 / exp_imgtag.php
Created March 12, 2013 08:06
HTMLファイル内のimgタグを抽出する ■使用例 $ php exp_imgtag.php < sample.html <img alt="・・・・ /> <img border="・・・ /> ・・・
<?php
$stdin = file_get_contents('php://stdin', 'rb');
preg_match_all('@<img .*?/>@isu' ,$stdin ,$regex, PREG_SET_ORDER);
foreach ($regex as $str) {
echo $str[0] . PHP_EOL;
}
?>