실천으로 아는 「PHP란」
이번에는 PHP의 기본적인 쓰는 방법에 대해 예를 보면서 배운 것을 정리하고 싶습니다. 「어쩐지 쓸 수 있다」가 되는 것이 목표입니다.
실천하는 것이 제일 몸에 붙습니다만, 읽는 것만으로도 이해할 수 있도록 씁니다.
대상·환경
기본 Linux 명령 (cd, ls, vim, grep, cat, echo 및 리디렉션)을 이해하는 사람
몰라도 알아보면 바로 나올까 생각합니다
쉘은 PuTTY를 사용합니다. 파일을 만들고 웹 서버에 업로드하여 브라우저에서 보는 방법을 사용합니다.
실천
그럼 바로 봅시다.
나열된 코드는 PuTTY 내에서 vim ファイル名.php를 실행하여 편집하는 .php 파일의 내용입니다.
1
이것을 test1.php로 만듭니다.
<html>
<body>
1+2= <?php
echo(1+2);
?>
</body>
</html>
우선 PHP란 HTML에 임베드할 수 있어 웹 개발에 자주 사용되는 프로그래밍 언어인 것 같습니다.
PHP를 작성하는 경우 <?php로 시작하고 ?>로 끝나는 규칙이 있습니다.
그리고 스크립트의 끝에는 ";"가 필요합니다.
그리고 HTML이란, 웹 페이지를 만들기 위해서 사용되는 기본적인 마크업 언어인 것 같습니다.
대체로 보면 알 수 있습니다만, 즉 이 코드는 PHP로 쓰여진 명령도 내장되어 있는, HTML에 의한 Web 페이지용의 기술이다, 라고 하는 것이군요.
브라우저에서 보면1+2 = 3라고 표시되었습니다.
2
여기를 test2.php로 만듭니다.
<html>
<body>
<form method="GET" action=test3.php>
<div><input type="text" name="name">:Name</div>
<div><input type="text" name="age">:Age</div>
<input type="submit">
</form>
</body>
</html>
PHP가 아니므로 해설은 하지 않지만, 읽고 쓰기하면서 기억합시다!
브라우저에서 액세스하면 연령과 이름 입력 화면이 나옵니다.
입력하여 전송해 보면 ...
제출해도 오류가 발생합니다.
대상의 test3.php가 없기 때문입니다.
test3.php를 만드세요.
3
<html>
<body>
<h1>Name and Age</h1>
<div>name:<?php
echo $_GET["name"]
?></div>
<div>age:</div>
<form method="GET" action=test2.php>
<input type="submit">
</form>
</body>
</html>
글쎄, 이름만 나왔어. 나이를 내려면 어떻게 해야 하나요?
<div>age:<?php
echo $_GET["age"]
?></div>
<div>age:</div>로 끝나는 나이에 대한 표시를 이름과 같이 표시하도록 다시 작성하면 잘 작동합니다!
4
test4.php 만들기
<html>
<body>
<h1>shell command test</h1>
<div>passthru</div><pre><?php
passthru( "ls -alh");
?></pre>
<div>exec</div><pre><?php
exec( "ls -alh");
?></pre>
</body>
</html>
지금까지 PHP의 함수를 실행해 왔습니다.
passthru, exec도 PHP 함수이지만 둘 다 외부 프로그램을 실행하는 함수이며 여기에서는 Linux 명령을 실행합니다.
passthru는 표시가있는 실행이고 exec은 표시되지 않은 실행입니다.

5
이제 4를 적용하여 이름과 나이를 검색하고 등록할 수 있습니다.
그 전에 쉘에서 목록을 저장하는 파일을 만드십시오. 파일 이름은 age.csv입니다.echo "hayashi 85" >> age.csvecho "unknown 18" >> age.csv라는 바람에, 몇개의 이름과 나이를 공백 단락으로 한 데이터를 등록해 둡니다.
그런 다음 test2.php를 편집합니다.
<html>
<body>
<h1> search age </h1>
<form method="GET" action=test5.php>
<div><input type="text" name="search">:Name</div>
<input type="submit">
</form>
<h1> age submit </h1>
<form method="GET" action=test3.php>
<div><input type="text" name="name">:Name</div>
<div><input type="text" name="age">:Age</div>
<input type="submit">
</form>
</body>
</html>
다음과 같이 test5.php를 만듭니다.
<html>
<body>
<h1>Search Age</h1>
<div>keyword:<?php
echo $_GET["search"]
?></div>
<pre>
<?php
passthru("grep ".$_GET["search"]." age.csv");
?>
</pre>
<form method="GET" action=test2.php>
<input type="submit" value="back">
</form>
</body>
</html>
검색할 수 있습니까?
6
그럼 마지막으로 test3.php를 다시 작성하여 등록 화면을 만들어 보자!
또한 test2.php를 변경하여 test6.php로 날아가는 기능을 추가하고 test6.php에서는 모든 데이터를 표시하는 방법은 무엇입니까?
대답
등록
<html>
<body>
<h1>Name and Age</h1>
<?php
exec("echo \"".$_GET["name"]." ".$_GET["age"]."\">> age.csv");
?>
<div>name:<?php
echo $_GET["name"]
?></div>
<div>age:<?php
echo $_GET["age"]
?></div>
<form method="GET" action=test2.php>
<input type="submit" value="back">
</form>
</body>
</html>
목록 표시
test2.php
<html>
<body>
<h1> search age </h1>
<form method="GET" action=test5.php>
<div><input type="text"
name="search">:Name</div>
<input type="submit" value="search">
</form>
<h1> age submit </h1>
<form method="GET" action=test3.php>
<div><input type="text" name="name">:Name</div>
<div><input type="text" name="age">:Age</div>
<input type="submit" value="submit">
</form>
<h1> inspect entire list </h1>
<form method="GET" action=test6.php>
<input type="submit" value="watch">
</form>
</body>
</html>
test6.php
<html>
<body>
<h1>lists</h1>
<pre><?php
passthru("cat age.csv");
?></pre>
<form method="GET" action=test2.php>
<input type="submit" value="back">
</form>
</body>
</html>
잘 했니? 할 수 없어도 다시 확인하면 점점 알게 되므로 반복 연습합시다!
Reference
이 문제에 관하여(실천으로 아는 「PHP란」), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/ideagear/items/59a45a5190084fe3909b
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
그럼 바로 봅시다.
나열된 코드는 PuTTY 내에서
vim ファイル名.php를 실행하여 편집하는 .php 파일의 내용입니다.1
이것을
test1.php로 만듭니다.<html>
<body>
1+2= <?php
echo(1+2);
?>
</body>
</html>
우선 PHP란 HTML에 임베드할 수 있어 웹 개발에 자주 사용되는 프로그래밍 언어인 것 같습니다.
PHP를 작성하는 경우
<?php로 시작하고 ?>로 끝나는 규칙이 있습니다.그리고 스크립트의 끝에는 ";"가 필요합니다.
그리고 HTML이란, 웹 페이지를 만들기 위해서 사용되는 기본적인 마크업 언어인 것 같습니다.
대체로 보면 알 수 있습니다만, 즉 이 코드는 PHP로 쓰여진 명령도 내장되어 있는, HTML에 의한 Web 페이지용의 기술이다, 라고 하는 것이군요.
브라우저에서 보면
1+2 = 3라고 표시되었습니다.2
여기를
test2.php로 만듭니다.<html>
<body>
<form method="GET" action=test3.php>
<div><input type="text" name="name">:Name</div>
<div><input type="text" name="age">:Age</div>
<input type="submit">
</form>
</body>
</html>
PHP가 아니므로 해설은 하지 않지만, 읽고 쓰기하면서 기억합시다!
브라우저에서 액세스하면 연령과 이름 입력 화면이 나옵니다.
입력하여 전송해 보면 ...
제출해도 오류가 발생합니다.
대상의 test3.php가 없기 때문입니다.
test3.php를 만드세요.
3
<html>
<body>
<h1>Name and Age</h1>
<div>name:<?php
echo $_GET["name"]
?></div>
<div>age:</div>
<form method="GET" action=test2.php>
<input type="submit">
</form>
</body>
</html>
글쎄, 이름만 나왔어. 나이를 내려면 어떻게 해야 하나요?
<div>age:<?php
echo $_GET["age"]
?></div>
<div>age:</div>로 끝나는 나이에 대한 표시를 이름과 같이 표시하도록 다시 작성하면 잘 작동합니다!4
test4.php 만들기
<html>
<body>
<h1>shell command test</h1>
<div>passthru</div><pre><?php
passthru( "ls -alh");
?></pre>
<div>exec</div><pre><?php
exec( "ls -alh");
?></pre>
</body>
</html>
지금까지 PHP의 함수를 실행해 왔습니다.
passthru, exec도 PHP 함수이지만 둘 다 외부 프로그램을 실행하는 함수이며 여기에서는 Linux 명령을 실행합니다.
passthru는 표시가있는 실행이고 exec은 표시되지 않은 실행입니다.

5
이제 4를 적용하여 이름과 나이를 검색하고 등록할 수 있습니다.
그 전에 쉘에서 목록을 저장하는 파일을 만드십시오. 파일 이름은
age.csv입니다.echo "hayashi 85" >> age.csvecho "unknown 18" >> age.csv라는 바람에, 몇개의 이름과 나이를 공백 단락으로 한 데이터를 등록해 둡니다.그런 다음
test2.php를 편집합니다.
<html>
<body>
<h1> search age </h1>
<form method="GET" action=test5.php>
<div><input type="text" name="search">:Name</div>
<input type="submit">
</form>
<h1> age submit </h1>
<form method="GET" action=test3.php>
<div><input type="text" name="name">:Name</div>
<div><input type="text" name="age">:Age</div>
<input type="submit">
</form>
</body>
</html>
다음과 같이 test5.php를 만듭니다.
<html>
<body>
<h1>Search Age</h1>
<div>keyword:<?php
echo $_GET["search"]
?></div>
<pre>
<?php
passthru("grep ".$_GET["search"]." age.csv");
?>
</pre>
<form method="GET" action=test2.php>
<input type="submit" value="back">
</form>
</body>
</html>
검색할 수 있습니까?
6
그럼 마지막으로 test3.php를 다시 작성하여 등록 화면을 만들어 보자!
또한 test2.php를 변경하여 test6.php로 날아가는 기능을 추가하고 test6.php에서는 모든 데이터를 표시하는 방법은 무엇입니까?
대답
등록
<html>
<body>
<h1>Name and Age</h1>
<?php
exec("echo \"".$_GET["name"]." ".$_GET["age"]."\">> age.csv");
?>
<div>name:<?php
echo $_GET["name"]
?></div>
<div>age:<?php
echo $_GET["age"]
?></div>
<form method="GET" action=test2.php>
<input type="submit" value="back">
</form>
</body>
</html>
목록 표시
test2.php
<html>
<body>
<h1> search age </h1>
<form method="GET" action=test5.php>
<div><input type="text"
name="search">:Name</div>
<input type="submit" value="search">
</form>
<h1> age submit </h1>
<form method="GET" action=test3.php>
<div><input type="text" name="name">:Name</div>
<div><input type="text" name="age">:Age</div>
<input type="submit" value="submit">
</form>
<h1> inspect entire list </h1>
<form method="GET" action=test6.php>
<input type="submit" value="watch">
</form>
</body>
</html>
test6.php
<html>
<body>
<h1>lists</h1>
<pre><?php
passthru("cat age.csv");
?></pre>
<form method="GET" action=test2.php>
<input type="submit" value="back">
</form>
</body>
</html>
잘 했니? 할 수 없어도 다시 확인하면 점점 알게 되므로 반복 연습합시다!
Reference
이 문제에 관하여(실천으로 아는 「PHP란」), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ideagear/items/59a45a5190084fe3909b텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)