読者です 読者をやめる 読者になる 読者になる

感謝のプログラミング 10000時間

たどり着いた結果(さき)は、感謝でした。

How to read RSS file in PHP

PHP
<スポンサーリンク>

This is a PHP sample of how to upload a file

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="Shift_JIS">
	<title> file sample </title>
</head>
<body>

<form action="fileupload.php" method="post" enctype="multipart/form-data">
<dl>
<dt>select some picture</dt>
<dd>
<input name="my_img" type="file" id="my_img" size="50" />
</dd>
</dl>
<input type="submit" value="send" />
</form>

this is PHP sample to read file.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="Shift_JIS">
<title> file upload </title>
</head>
<body>
<?php
$file = $_FILES['my_img'];
print('file name(name): ' . $file['name'] . '<br />');
print('file type(type): ' . $file['type'] . '<br />');
print('uploaded file(tmp_name): ' . $file['tmp_name'] . '<br />');
print('error content(error): ' . $file['error'] . '<br />');
print('size(size): ' . $file['size'] . '<br />');

//file upload
$ext = substr($file['name'], -4);
if ($ext == '.gif' || $ext == '.jpg' || $ext == '.png') {
	$filePath = './user_img/' . $file['name'];
	move_uploaded_file($file['tmp_name'], $filePath);
	print('<img src="' . $filePath . '" />');
} else {
	print('please upload the file extention is .gif or .jpg.  or png');
}
?>
</body>
</html>

enctype means "encode type",
We can't send a form as it is, so we have to work encoding.
if I use "multipart/formdata", I can send the file as it is.


■This is the sample of to read RSS file
hatena bookmark is Japanese popular web service to read hot entry.
I read its RSS using PHP.

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title> RSS Reader </title>
</head>
<body>
<?php
$xmlTree = simplexml_load_file('http://feeds.feedburner.com/hatena/b/hotentry');

foreach($xmlTree->item as $item) {
	$link = $item->link;
	$title = $item->title;
	echo '<dd><a href="' . $link . '" trget="_blank">' . $title . '</a></dd>';
}

?>
</body>
</html>
                                                          • -

I have studied programming in【184 hours in total】 since 2013.
To achieve my target, I need 【9816 hours】practice of programming.