Basic PHP Tutorial 4: Variables and Comments
Key Takeaways
Declares and uses variables and comments in PHP
Full Transcript
hello and welcome to the fourth PHP tutorial in this tutorial we're going to be talking a little bit on comments variables and just a little bit on like string concatenation as it's called but mostly how do you put variables with on into a string basically so with that let's hop right on into it the first thing is commenting there's two ways to comment then you can do a slash slash and that's good for a single line of comments as you can see when you hit Enter and you come down no longer is it the same color and now it's going to throw you some errors whereas it's just a single comment let's just do echo low we'll save that put it back to the server pop over to our old one refresh you see hello but you don't see the this comment here now if you're planning on commenting just like a huge comment or you want to put up like a list like sometimes in tutorials I want to put up a whole different like a whole bunch of examples or defining characteristics for something and you want it you'll just want to be able to list things out without doing slash slash this slash list you know the way to do that to do a multi-line comment is a forward slash star and then wherever you want to end it star forward slash in everything in here is now classified as a comment so we can save that and throw that back to the server refresh and we still have hello so that's comments now I'm gonna go ahead and delete that since wasting space so the next thing is variables so variables are defined in the following way use dollar sign and they can start with any kind of letter uppercase or lowercase and then also you can start with an underscore you can't start with a space and you can't start with a number so if you really wanted to start with some sort of digit you know you can right out to or you can do like underscore to something like that but yeah you just can't start with the digit as you can see it's already getting angry with me so that's how you to find a variable so we're just going to literally call this bar 1 then you use an equal sign and you're basically it's like an assignment operator basically you're assigning something to this variable and what we want to assign the bar 1 is how are you so the way that you can use variables at least in the echo statement is let's say you want to do hello how are you so you want to say hello and then what you'll do is to put it like something to another like to put a variable to concatenate the variable to the string use a period that's called a full stop and then you can just put the variable out now what this is going to do is make somewhat of an ugly addition like in Python you can use either the plus sign or the comm on that common just automatically add to space and the plus sign is not whereas here in PHP you just have the full stop so when we refresh this and we didn't add a semicolon I'm sure yep when we refresh this you'll see the it's kind of jammed together so naturally what you'll have to be used to doing is spacing things so hello and really you want to hear space save that and you'll put that up to the server and you'll refresh and now you see hello space how are you it just looks better and so that's how you add variables and echo out variables naturally as you get further into this with you know using more HTML concepts and stuff it becomes really useful to be echoing out various variables so now just to expand this just slightly further let's say the first variable we want to use is going to be name and we're going to say name is Harrison and we'll do age equals 19 and let's say you want to do you want to echo out hello and you want to build their name and then you want to say your ages and then you want to bold the age you can probably guess sort of how we might do this or a wholly how we might do this but just as a quick example it's good to just kind of run through this stuff so let's say we're going to do this hello and then we want to do the bold the name Harrison but when you spit out a variable you can't you know put unless you put literally the strong tags in front of the variable you could do it that way but instead what we're going to do is just do strong and then we're gonna append name and then again we want to append some more tax you'll have to add this space obviously we already out of the space here and then we wanted to go ahead and close off the strong tag so we just want to bold the name then we wanted to say you are and then again we want the strong tag close that off period age period we already opened up that parentheses early Y quotes there and then we'll just do years for it okay so now it should say hopefully oh we better close off the next strong tag close that off so now it goes hello initiates the strong puts in the name of Harrison space you are initiate strong again and then says the age whatever that is and then years old so we'll save that put that up to the server refresh and sure enough it builds just the name and the age so those are the basics of defining variables doing comments and kind of you know starting to work in variables and to string tags and all of that so as always thanks for watching and until next time
Original Description
Link to the full playlist:
http://www.youtube.com/playlist?list=PLQVvvaa0QuDcYpcjrNB43_iKqla5UeQw_
Sentdex.com
Facebook.com/sentdex
Twitter.com/sentdex
Variables and Comments within PHP.
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 19 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
▶
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
🎓
Tutor Explanation
DeepCamp AI