

プログラミング初心者の僕がPHPで作ったポートフォリオについて紹介します。
・PHPを勉強したい人
・PHPを使ってポートフォリオを作成しようとしている人
・PHPをこれから勉強しようとしているひと
この記事の目的
PHPとは
PHP (PHP: Hypertext Preprocessor を再帰的に略したものです)
広く使われているオープンソースの汎用スクリプト言語です。 PHP は、特に Web 開発に適しており、HTML に埋め込むことができます。
PHPにできることは?
PHPでは主にサーバーサイドでの活用に焦点が 当てられているため、フォームからデータを取得したり、動的にページ の内容を生成したり、クッキーを送信・受信するといった他のCGI プログラムに出来ることは全て行うことが出来ます。
主にバックエンド、サーバーサイド系のプログラミング言語となります。Mysqlなどのデータベースのどとよく一緒に使われます。
PHPポートフォリオ例

If文を使った年齢の判断
こちらはPHPの中のIf文を使い20歳以上ならばお酒を買うことが出来て未満ならば購入できないというプログラムを書きました。
<?php
function myAge($age){
if ($age >= 20) {
echo "<div class= 'alert alert-success mx-auto mt-3' >
<strong>成人です</strong> 'あなたはお酒を飲むことができます'</strong>
</div> ";
}else{
echo "<div class= 'alert alert-success mx-auto mt-3'>
<strong>未成年者です</strong>'あなたはお酒を飲むことができません'
</div>";
}
}
?>
<!doctype html>
<html lang="en">
<head>
<title>Title</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="card text-center mt-5 mx-auto w-auto">
<form action="" method="POST">
<div class="card-header ">
20才を超えていますか?
</div>
<div class="card-body">
<div class="form-group">
<label for="" name="">ここに何歳を入力してください</label>
<input type="number" class="form-control" name="age">
<br>
<button type="submit" name="submit" class="btn btn-success btn-block">Submit</button>
</div>
</div>
</form>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
<?php
if(isset($_POST['submit'])) {
$input = $_POST['age'];
myAge($input);
}
?>
If文について詳しく気になる方は
$を入力した数字だけloopさせてみる
https://sosotake.com/PHP/loop.php
Loopを使い$を自分を入力した数だけloopできるプログラムをかきました。
<?php
function loop($input){
for($x = 1; $x <= $input;$x++){
for ($y = 1; $y <=$x;$y++){
echo "$";
}
echo "<br>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<body>
<div class="container w-50 text-center mx-auto mt-5">
<form action="" method="post">
<label for="">Enter a number</label>
<input type ="number" class="form-control" name="user_input"></input>
<br>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<?php
if(isset($_POST['submit'])){
$input =$_POST['user_input'];
loop($input);
}
?>
</body>
</html>
Loopが気になる方は
自己紹介プログラム
・名前
・出身
・年齢
この3つを使った自己紹介ができるプログラムを書きました。
<!doctype html>
<html lang="en">
<head>
<title>Title</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="card mx-auto text-center w-50 mt-5">
<form action="" method="post">
<div class="card-header danger">
<h1>Introduction</h1>
</div>
<div class="card-body">
<div class="form-group">
<label for="">Your name</label>
<input type="text" class="form-control" name="name" placeholder="Your name">
<label for="">Where are you from?</label>
<input type="text" class="form-control" name="originally" placeholder="originally">
<label for="">Your age</label>
<input type="text" class="form-control" name="age" placeholder="Your age">
<!-- <select class="form-control" name="age" >
<option value="未選択" name="men">Men</option>
<option value="20代" name="woman">woman</option>
</select> -->
<br>
<button type="submit" class="btn btn-danger btn-block" name="submit">Submit</button>
</div>
</div>
</form>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$originally = $_POST['originally'];
$age = $_POST['age'];
echo "I'm going talk about my self.";
echo "<br>";
echo "Hi hello my name is ",$name;
echo "<br>";
echo "I'm from ", $originally;
echo "<br>";
echo "My age is ",$age;
}
?>
https://sosotake.com/Hello.php
入力した文字を入力した数だけ出力する
入力した文字を入力した数だけ出力するプログラムを書きました。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="" method="post">
<label for="">What do you wanna loop?</label>
<br>
<input type="text" name="sentence" id="">
<br>
<label for="">How many times do you want to me loop?</label>
<br>
<input type="number" name="number" id="">
<br>
<br>
<button type="submit" name="submit">start looping</button>
</form>
<?php
if(isset($_POST['submit'])){
$sentence =$_POST['sentence'];
// sentense we want to top
$number =$_POST['number'];
// many times the
for($x = 1; $x <= $number; $x++){
echo $sentence;
echo"<br>";
}
}
?>
</body>
</html>
PHPポートフォリオ作り方

まずは環境を環境構築から
PHPを動かすためにXAMPPのインストールをしました。
最も人気のある PHP 開発環境です
XAMPP は、完全に無償で MariaDB、PHP、および Perl を含んだ、簡単にインストールできる Apache ディストリビューションです。
PHPの勉強とBootstropの勉強を独学を含めて2か月
FFFTPを使いアップロード
SURVERの取得
これらをしました。
ほとんど自分で調べてやりました。
PHPポートフォリオ未経験

環境構築→ポートフォリオの作成→アップロードをするまでに2~3か月ぐらいかかりました。
今思えばなかなか苦労しましたがまだ業務レベルにはまだまだですね。
業務未経験でエンジニア転職に少しでも近づきたい方にはポートフォリオのレベルを上げることです。
独学もしくはプログラミングスクールに入るかのどちらかがおススメのです