<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample01</title>
</head>
<body>
3000円から100円引きした場合、
<?php echo floor(100 / 3000 * 100); ?>%引き
<br>
<?php echo ceil(3.33);?><br>
<?php echo round(3.66, 1);?><br>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample01</title>
</head>
<body>
<?php
$date = sprintf('%04d.%02d.%02d', 2021, 8, 3);
echo $date
?>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample01</title>
</head>
<body>
<?php
$success = file_put_contents('data/news.txt', 'ホームページをリニューアルしました。');
if($success){
echo 'ファイルの書き込みが完了しました。';
}else{
echo 'ファイルの書き込みが失敗しました。';
}
?>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample01</title>
</head>
<body>
<?php
$news = file_get_contents('data/news.txt');
echo $news;
// この関数でもファイルの読み込みができる
readfile('data/news.txt');
?>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample01</title>
</head>
<body>
<?php
$xmlTree = simplexml_load_file('rss.xml');
foreach ($xmlTree->channel->item as $item):
?>
・<a href="<?php echo $item->link ?>"><?php echo $item->title ?><br>
<?php endforeach;?>
</body>
</html>