質問編集履歴
2
DB情報
test
CHANGED
File without changes
|
test
CHANGED
@@ -92,6 +92,55 @@
|
|
92
92
|
?>
|
93
93
|
```
|
94
94
|
|
95
|
+
### 修正を試みたコード
|
96
|
+
```ここに言語を入力
|
97
|
+
<?php
|
98
|
+
$url1 = [
|
99
|
+
'',
|
100
|
+
'',
|
101
|
+
'',];
|
102
|
+
|
103
|
+
// insertの準備
|
104
|
+
$stmt = $dbh->prepare('insert into hlxclitx_feed_rss (post_thumbnail, site_title, link,description) values (?, ?, ?, ?)');
|
105
|
+
|
106
|
+
// URLのループ開始
|
107
|
+
foreach ($url1 as $url) {
|
108
|
+
if (($rss = @simplexml_load_file($url)) === false) continue;
|
109
|
+
// URL固有のデータを取得(これ、全部必要なの?そもそも全部存在するの?)
|
110
|
+
// サイトの内容を個別記事の内容は変数名を変えないとダメ(上書きされてしまう)
|
111
|
+
$site_thumbnail= $rss->channel->thumb;
|
112
|
+
$site_title = $rss->channel->title;
|
113
|
+
$site_link = $rss->channel->link;
|
114
|
+
$site_description = $rss->channel->description;
|
115
|
+
$site_description = strip_tags($site_description);
|
116
|
+
if ($desW != 0) $site_description = mb_strimwidth($site_description, 0, $desW, "…",'utf-8');
|
117
|
+
$site_thumb = '/images/dummy_thumbnail.jpg';
|
118
|
+
// サイトごとに表示するなら、サイトタイトル表示はこの位置
|
119
|
+
printf('<h2>%s</h2>', $site_title);
|
120
|
+
|
121
|
+
$count = 0
|
122
|
+
// 個別記事のループ開始
|
123
|
+
foreach ($rss->item as $item) {
|
124
|
+
if (++$count > 8) break;
|
125
|
+
$thumb = $item->thumb;
|
126
|
+
$title = $item->title;
|
127
|
+
$link = $item->link;
|
128
|
+
$description = $item->description;
|
129
|
+
$dc = $item->children('http://purl.org/dc/elements/1.1/');
|
130
|
+
$date = date('Y-m-d H:i:s', strtotime($dc->date));
|
131
|
+
|
132
|
+
// データを取得し終えたら、その内容を executeメソッドで書き込む
|
133
|
+
$stmt->execute([$site_thumbnail, $site_title, $link, $description]);
|
134
|
+
// 取得した記事データの表示
|
135
|
+
if ($count === 1) print('<ul>');
|
136
|
+
printf('<li>%s:%s:%s</li>', $title, $link, $date);
|
137
|
+
} // 個別記事のループ終了
|
138
|
+
if ($count) print('</ul>');
|
139
|
+
} // URLのループ終了
|
140
|
+
?>
|
141
|
+
|
142
|
+
```
|
143
|
+
|
95
144
|
### 試したこと
|
96
145
|
```ここに言語を入力
|
97
146
|
$stmt = $pdo->prepare('insert into teblename (data) values (?)');
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -130,5 +130,7 @@
|
|
130
130
|
|
131
131
|
```
|
132
132
|
|
133
|
+
### DB情報
|
134
|
+
データベース名 hlxclitx_feed_rss
|
135
|
+
テーブル post_thumbnail, site_title, link,description
|
133
136
|
|
134
|
-
![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-01-15/15dbc77a-1723-4f5b-b147-36765a0366e9.png)
|