1 00:00:00,110 --> 00:00:04,590 Most of the time you hear of PHP as a language for creating web pages. 2 00:00:04,590 --> 00:00:06,940 But PHP isn't limited to the web, 3 00:00:06,940 --> 00:00:10,950 PHP is also very useful as a general scripting language. 4 00:00:10,950 --> 00:00:15,884 You can write and run scripts directly on your computer without a web browser 5 00:00:15,884 --> 00:00:19,600 using what's called the command line interface or CLI. 6 00:00:19,600 --> 00:00:24,453 We'll start our projects using the CLI in the workspaces console before adding them 7 00:00:24,453 --> 00:00:27,120 to a web page in the last section. 8 00:00:27,120 --> 00:00:31,480 To follow along in your own workspace, click the launch workspace button. 9 00:00:31,480 --> 00:00:32,200 If you're looking for 10 00:00:32,200 --> 00:00:35,930 a little more explanation on workspaces, check the teacher's notes. 11 00:00:35,930 --> 00:00:36,790 Let's get started. 12 00:00:38,480 --> 00:00:40,480 When learning a new programming language, 13 00:00:40,480 --> 00:00:44,310 it's a tradition to start with a simple hello world program. 14 00:00:44,310 --> 00:00:47,354 So let's start off by creating a new file named Hello. 15 00:00:50,265 --> 00:00:53,009 We'll give this the extension .php. 16 00:00:53,009 --> 00:00:58,920 You place php code inside what's called a code block. 17 00:00:58,920 --> 00:01:05,413 Much like HTML tags, the opening tag is <?php, 18 00:01:05,413 --> 00:01:09,211 and the closing tag is ?>. 19 00:01:09,211 --> 00:01:12,800 We then place our code within this code block. 20 00:01:12,800 --> 00:01:15,740 To display something to the screen we use the echo command, 21 00:01:16,860 --> 00:01:19,620 followed by whatever we want to display. 22 00:01:19,620 --> 00:01:21,585 In this case we'll type, Hello World. 23 00:01:21,585 --> 00:01:25,720 We'll surround this text with quotes and end the line or 24 00:01:25,720 --> 00:01:27,220 statement with a semicolon. 25 00:01:28,240 --> 00:01:33,240 A statement in programming can be defined as an instruction to perform a specified 26 00:01:33,240 --> 00:01:38,898 action, such as setting data, retrieving data, performing a calculation and so on. 27 00:01:38,898 --> 00:01:44,220 Statements in php almost always need to end with a semicolon. 28 00:01:44,220 --> 00:01:46,660 Now let's run our script in the console. 29 00:01:46,660 --> 00:01:50,570 If your console is not visible go to View, Show Console, 30 00:01:52,360 --> 00:01:58,330 then type php followed by a space, and then the name of the php file hello.php. 31 00:01:58,330 --> 00:02:03,030 This tells the console we want to use the php command 32 00:02:03,030 --> 00:02:07,930 line interface to process the file, hello.php. 33 00:02:07,930 --> 00:02:12,350 This is often called running a script or executing the script. 34 00:02:12,350 --> 00:02:14,730 Don't worry, scripts aren't hurt when you execute them. 35 00:02:15,800 --> 00:02:19,080 In the console we see the output, Hello World, but 36 00:02:19,080 --> 00:02:22,480 not the php tags or the echo command. 37 00:02:22,480 --> 00:02:26,868 This is because the php command line interface, or cli for short, 38 00:02:26,868 --> 00:02:33,225 processes the php code and returns only the output. 39 00:02:33,225 --> 00:02:37,245 What we're talking about php code, let me point out that with few exceptions, 40 00:02:37,245 --> 00:02:43,690 php does not care about extra whitespace such as spaces, tabs, or blank lines. 41 00:02:43,690 --> 00:02:47,700 You can have things all smooshed up together, or spread out, however you want. 42 00:02:47,700 --> 00:02:52,572 But remember, with great power comes great responsibility. By following 43 00:02:52,572 --> 00:02:55,713 best practices and spacing your code clearly, 44 00:02:55,713 --> 00:03:01,310 you can make your code easier to read for others and for your future self. 45 00:03:01,310 --> 00:03:02,370 Congratulations! 46 00:03:02,370 --> 00:03:03,970 You've written your first php script. 47 00:03:05,190 --> 00:03:08,960 To get the most out of this course, let me provide a few tips. 48 00:03:08,960 --> 00:03:12,470 If you hit a part of the video where you're struggling to follow along, 49 00:03:12,470 --> 00:03:15,770 you can always slow down or speed up the videos. 50 00:03:15,770 --> 00:03:19,560 Also, feel free to watch the videos more than once. 51 00:03:19,560 --> 00:03:23,770 Furthermore, I've included additional information in the teacher's notes. 52 00:03:23,770 --> 00:03:26,600 So don't forget to check those out as well. 53 00:03:26,600 --> 00:03:30,670 If you don't write your code exactly right, php will give an error. 54 00:03:30,670 --> 00:03:33,100 If you want to learn more about error handling, 55 00:03:33,100 --> 00:03:35,830 check out the workshop in the teacher's note. 56 00:03:35,830 --> 00:03:40,460 And finally, not only is the php community as a whole fabulous, 57 00:03:40,460 --> 00:03:45,180 you also have an awesome community of fellow students here at Treehouse 58 00:03:45,180 --> 00:03:48,310 who can help you with questions that you might have. 59 00:03:48,310 --> 00:03:50,730 Sometimes it just takes another perspective 60 00:03:50,730 --> 00:03:53,070 to help you really understand a new concept.