-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeTempfile.php
More file actions
68 lines (62 loc) · 2.21 KB
/
Copy pathmakeTempfile.php
File metadata and controls
68 lines (62 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
require_once './getResource.php';
require_once './getArticle.php';
//値の初期化
$log = ARTICLE_DIR . ARTICLE_LOG;
$newArticle = ARTICLE_DIR . DOWNLOAD;
//今まで取得したURLの一覧のファイルがなければ生成
if (!file_exists($log))
{
touch($log);
}
//今回取得したURL一覧のファイルがなければ生成
if (!file_exists($newArticle))
{
touch($newArticle);
}
$apiSearch = convertURL2QiitaParameter(ARTICLE_ADDRESS);
$data = getArticleInfo($apiSearch);
//ファイルオープン
$na = fopen($newArticle, 'w');
//$articleFileはget-resource.phpで取得したファイル
//文字列からいい感じに分割し、配列にする
$articleFile = explode('位 <a href="', $articleFile);
//配列から必要な情報(タイトルとタグ)を取得
foreach ($articleFile as $k => $v)
{
//正規表現を使っていい感じにURLを取る
preg_match('/https:\/\/qiita.com\/([a-zA-z0-9-\/]*)"/', $v, $match);
//該当するものがあった場合
if (!empty($match))
{
//URLの後ろのダブルクォーテーションを除く
$address = str_replace('"', '', $match[0]);
//今まで取得したURLの一覧をオープン
$l = fopen($log, 'r+');
//一覧の最後の行に至るまで処理を続ける
while (!feof($l))
{
//一行読み込む
$tmp = fgets($l);
//取得した一行から改行を除く
$tmp = str_replace(PHP_EOL, '', $tmp);
//URLがすでに取得したものだったら処理を終了させる
if ($tmp == $match[1])
{
break;
}
//最後の行まで読みんでもなかった場合
if (feof($l))
{
//今まで取得したURL一覧に記載
fwrite($l, $match[1]."\n");
//今回取得したURL一覧に記載
fwrite($na, $address."\n");
}
}
//処理が終わったら、ファイルを閉じる
fclose($l);
}
}
//処理が終わったら、ファイルを閉じる
fclose($na);