Basic PHP Syntax - PHP 8 Tutorial
VloĆŸit
- Äas pĆidĂĄn 12. 06. 2024
- Let's write some PHP & go over the basic syntax. After this video, you will be able to concatenate & print text to the browser, declare & use variables, use variables within strings & embed PHP within HTML. In all of my videos, I cover a lot of small details that in my opinion are very important so I recommend watching the video fully.
SOME OF THE WAYS YOU CAN SUPPORT THE CHANNEL
đ Smash the like button
đ€ Subscribe to the channel & turn the notifications on
đŹ Post comments, any feedback is greatly appreciated
â Become a Patreon: / programwithgio
THANK YOU!
LESSON 1.2
Course Outline - github.com/ggelashvili/learnp...
Course Playlist - âą Learn PHP The Right Wa...
CHAPTERS
00:00 Intro
00:41 Basic Syntax
01:58 Hello World
03:22 Run PHP In Terminal
03:50 Print vs Echo
05:18 Escaping Quotes
05:45 Variables
06:26 $this variable
06:48 Assigning by Value vs Reference
07:45 Variables Within Text
08:52 PHP In HTML
10:45 Comments
I highly recommend this video on the Basics of PHP Syntax to total beginners and anyone who lacks a clear starting point, as it is truly helpful.
Thank you đ
Well, considering I'm currently in an internship and trying to catch up to my mentors, this series is an absolute gold mine. One of my mentors recommended it and I couldn't be more satisfied by it. Thank you for the invaluable work you put into this!
Thank you & send my thanks to your mentors, really appreciate it đ
Same đ€
This will help out beginners immensely, I wish I had these basics when I just started, would've helped me out a lot!
Huge thanks to Gio for the invaluable knowledge shared in these tutorials!
You're welcome
Learning PHP language is very pleasant thanks to this channel.
Glad to hear that, thank you
lots of great stuff, very detailed. you're the best PHP teacher I've ever encountered.
Thank you đ
These are legit the best coding practices I have ever learned, and you just tackled printing and variables. I'm commited to finish this tutorial :)
Glad you like it, welcome aboard đđ
The best explanation way I have ever attended on CZcams, a lot of information that I did not find in another youtube channel, I really like your way of explanation.
Thank you, Gio.
Thank you đ
Hey Gio! You deserve Millions of Subscribers. Keep it up and bring more courses like this 'cause I'm really enjoying this course.
Thank you, I'm glad that you like my tutorials đ
Wow ... the amount of information you have is insane!!! It shows that you really know what you are talking about. Thanks for this valuable series! :D
Thank you. I spend a lot of time preparing videos, I don't know everything by heart :)
This is the third tutorial I'm on, and I had to quit the other two (which are supposedly for beginners), because of deprecated code and no fix for the problems. One thing I wondered was why there was no php closing tag used. Nobody ever explained it. You are the FIRST to actually explain why! Thank you!!!
It's one of the reasons why I made this course and put in so much effort. Glad you like it and find it useful, feel free to ask any questions as you are going through the course đ
That's awesome, I really love your teaching style. Keep up the good work.
Thank you đ
Good to see new content coming out, PHP is still my favorite language. Just feels good to me, not sure why!
PHP is great and it is my favorite language as well. Not only because it pays the bills but also because of the community & its huge ecosystem. PHP is constantly being improved & updated & is just great to work with.
Very Clear. I liked your introduction and how detailed you are. Starting right at the beginning is frustrating but absolutely necessary as you say
Glad you liked it, thank you đ
Very clear explanation you deserve more audience.
You earned a new subscriber.
Keep up the good work đđ
Thank you so much đ
I like how you speak slowly and explain everything . I will complete the full course .. Keep up the good work
Thank you đ
Perfect explanation đ
Glad you liked it
php file:
If you want your file to be interpreted as php then your file must end with that php and not with that html. php files can also have html, CSS, JavaScript in them.
php tag:
php opening and closing tag is and php interpreter interpreted the code between opening and closing tag. But if your file entirely contain 100 percent php code then you do not need the closing tag and that is to make sure that no accidental whitespace or new lines are added after the php closing tag which could mess up your website.
Semicolon:
php closing tag will automatically assume the semicolon on the last line.
So basically you do not need semicolon the Last line of php statement. This is useful when you are embedding php with html and it's just a single line in those case s you do not need the semicolon but if you have multiple lines though it's a good idea to stay consistent and just use the semicolon.
php code execute:
You could execute your php script within your terminal. If you open xampp control panel and click on shell on here this will bring up the terminal. We need to cd into our project directory which is htdocs program with project name and then you could run php files using the php command and that will give you the output. So you could basically execute your php code in command line if you want.
You could also use print to print something which essentially is the same thing as echo.
Difference of echo and print:
Print has a return value of 1 for that reason here I give an example like
I do echo and then print that will print out hello world and then append one at the end because this expression itself return 1 this means that print could be used within expressions while echo can not for example if we did this the other way print echo "hello world" and this would not work and we would get the syntax error.
Echo could print multiple values while print can not.
for example
echo "abc", "xyz";//works
print "abc", "xyz";//does not works
Echo is marginally faster than print.
variable
Vraible declared with dollar sign($).First character start with a-zA-Z_ and then other character from a-zA-Z_0-9.No space and no special character are allowed. This is a object so you do not assign $this.
Variables in php are by default assign by value .Let me show you what I mean
so if we have a variable called x which equals to 1and then we have a variable y which equals o x and then we change the value of x to 3 and then we print y what will be printed is 1 and not 3 that is because variables are assigned by value.On the other handif you actually wanted y to change whatever x cahnges then we need to assign variables by reference instead of value. Assign a variable by reference,you need to add ampersand righ here so now y is equal to reference variable x so anytime x cahnges the y will also change and now y is equal to 3.
Comments:
There are two types of single line comments that are // your comments and #your comments.
Multiline comments is /* comment here */. Nested multiple comments are not allowed.
wow
Thanks. I didn't know about the reference. Looking forward to finish this amazing course :P
You're welcome. Glad it was useful đ
very good, i'm wathching from Brazil, thank you.....congratulations for your channel!
Thank you & greetings to you my friend, love Brazil (my favorite national football team)
Once again, very clear and nicely explained. Plus, I enjoyed learning the concepts that are not very widely taught in other resources. keep it up! :)
Thank you đ
thank you very much for this excellent course.
You're welcome đ
Real Nice!
Liked and subscribed.
Thank you đ
Thank you for your great contribution !!
đđ
TNice tutorials comnt from you is legendary. Uncomplicated like your video!!!
Glad you like them, thank you đ
Very helpful tutorial â€
đđ
I have been developing in PHP for some years . . . and didn't know about ONLY have an opening PHP tag, for files that ONLY contain PHP. A great tutorial.
Thank you đ
Excellent! Thanks, Gio!
You're welcome
very powerful tutorial :)
very clear explanation sir
Thank you đ
learning lots of cool little details here!
Glad to hear that đ
Keep up the good work. â€
Thank you, I'll try my best đ
Thx for the great video
You're welcome
Thank you for this wonderful and very knowledgeable đ PHP learning series.
You're very welcome
great. thank you.
You're welcome
great tutorial. Thanks
You're welcome
U are the best â€
Thank you
thank you again
Always welcome
thank you so much
you're welcome
great!
i have started learning it i will come back when i finish it! đ
đ€đ€
finally i found a good PHP course.
Happy to hear đ
thank you
You're welcome
Awesome :)
Thank you. Cheers
thanks a lot
You are welcome
Great Master
đđ
Realy cool
Thank you
Good for beginners.
Glad you think so
Wow! I just learned that in PHP variables are assigned by value by default and not by reference đź
Already seeing some progress, can't wait for more đ
Happy to hear, keep going đ
You can also use a period to concatenate a string: $s = "Hello " . "World";
Yup I show that in the video as well.
Working on a laravel project and struggling with syntax hope this will help
Hope too
Hi, there. I am absolutely new in this. I have already installed VSC, is it ok for php? You didn't recommended in the video...
It's fine, I don't use VSC, I use phpstorm but a lot of devs use vscode & I think its fine. It just may not have all the features phpstorm has.
can i use vs code as IDE while following ur tutorial?
beginner here thank you
You can use any code editor you like
How did you make the browser auto update the output of the code?
Power of editing
Hello ,pleasehow can i fix the port problem definitly in xampp,cause all the time i open xampp i have to change port number
Maybe something else is running on that port that is holding it up?
Is there a reference that gives us a list of course in order of the video names?
Yes, the link to the repo is in the description. It contains outline of all videos with title and link
Can you please confirm that the link to your patreon account works? I hit the url but it seems to be broken or something.
Yes works fine on my end, just tested it as well
pls which text editor is suitable to code php
Phpstorm in my opinion is the best
How to make errors to appear in a browser? I've edited php.ini file and set error_reporting = E_ALL and display_error = On, but nothing changed. The program is still crashes silently.
Did you restart Apache?
Many jobs opportunities using PHP from where I am located. I was learning Node.js and I will still practice it but I feel like I should learn PHP and not pay attention to those who say that PHP is dead.
Thats a good strategy, you should go based on demand & if in your location PHP is on demand then it makes sense to learn PHP
Hi Gio. Nice videos. I created php functions to be used to generate dynamic html but i feel is the wrong practice. I watched your videos on slim and twig but couldnt wrap my head around so im using php template for the view rendering. Is there a way i can use slim php with React (acting as the dynamically generated html for the views) where if render view eg home.php with some fetched db data the React takes the $data which I'd json encode in the home.php view and pass it as a prop to a React component to dynamic generate the views. In short how can i merge slim php with react
You can use PHP with React but you would need to use PHP as an API layer and pass data to your react via ajax calls. Its a bit complicated to set it up but its certainly possible. You can look into Inertia.js for Laravel which allows you to pass down to react components directly from controllers similar to how you would pass it down to regular views
@@ProgramWithGio this is great! Thank you, mate.
â€ïžâ€ïžâ€ïžâ€ïžâ€ïž
đđđ
Hi Gio, one thing about the semicolon, I saw in following videos that when you declare function or classes you don't use the semicolon at the end, why that? Isn't it an end of a statement?Indeed if I put it in those occasions it seems that the script doesn't work, I'm quite confused.
Hey, you don't need semicolon at the end of }. Can you point me to timestamp on the video on what part you are referring to? You don't need semicolon on single line expressions like this
@@ProgramWithGio
I didn't mean u put semicolon at the end of }, I was askin' why is that in general.
"Hey, you don't need semicolon at the end of }" --->why is that? I can't understand where to put semicolons exactly.
I meant that in following videos of yours there were (indeed) no semicolon at the end of } but I cannot understand why if we're saying that we must put them after every statement.
There were something like this(but also seeing other codes):
@@rosarioveneruso9928 } on its own is not a statement so yea you don't put a semicolon there. It's just a closing bracket. If that were case then you would need to put semicolon at the end of each line including the if() {.
P.S. I don't think the above code is from my lesson.
@@ProgramWithGio It isn't , i was just an example(i wrote "somethin' like"), the point was that it wasn't clear to me when/where put semicolon.
"} on its own is not a statement so yea you don't put a semicolon there" I meant the two brackets with what is inside of it, don't we count that as a statement? The block inside of it is not a/a series of instruction/s?
@@rosarioveneruso9928 I would watch lesson about expressions in this series, it might help. You just don't put semicolons at the end of brackets, idk if there is a list of things that you can't put semicolons on but that's one of them. Whatever is contained within control block (within brackets) at the end of those lines you put semicolon, they are usually expressions.
Joel Karr to be fair I learnt loads
Was this directed to me or someone else? Either way, thank you đ
holy shit you went with php storm. Great software but expensive as heck and probably not something a new user would invest in.
Sure, you can use whatever IDE you want, phpstorm is not a requirement. It's just what I use and am comfortable with
Hi I am a completely beginner for PHP, but the tutorial is really too fast for me :( a bit frustrated
Hello. You can slow it down by clicking on the âïž icon and set playback speed to 0.75x or 0.5x. I apologize if it's too fast, I've made some editing mistakes where I cut out all empty spaces.
Srry boys but echo ("Hello {$variable}") is deprecated since php 8 so if you are searching why vscode gives u a warning in this line of code now you know why
Nope, that is not deprecated in PHP 8 and is perfectly valid. Did you define the variable? What error are you getting? Maybe you are referring to PHP 8.2 which deprecates this: "${variable}" but "{$variable}" should still work
@@ProgramWithGio works but vscode says it's deprecated since php 8
@@teacupentertaining6073 I don't see it in the php documentation as being deprecated. You can see here what's deprecated in 8.2: www.php.net/manual/en/migration82.deprecated.php
i am study inglish language in this video
That's awesome
wcan i get like to the creator of this video,im learning php anow, im am lat?
I'm the creator of the video, what's up?
how to free use PHPStorm lifetime?
you buy it
I was a bit confused at first until I realized that you do not know the meaning of the symbol quotes in English. ' = apostrophe, " = quotes and "" = double quotes.
Thanks, English isn't my first language, but in PHP we usually call it all quotes (single, double) and saying apostrophe usually confuses people more since most know it as "quotes" and either single or double quote works in most cases.
Php8?
Yup, we upgrade to PHP 8, & to 8.1 in following videos. At the time of recording of this video 8.0 wasn't released yet.
echo print('!!');
Good job bro, JESUS IS COMING BACK VERY SOON; WATCH AND PREPARE
Ok, thanks
á„áá ááááá áźáá áźá ? á
áá đ
@@ProgramWithGio áá„áȘáááąáá áááąá§ááá áá
á.áĄ. áášáááááá á ááá áĄáá„ááá, ááĄá á„áá ááŁáááááȘ á á áááá áááááááááááá áááá ááááŹá§áááĄ
@@user-hp4bx3gn6k ááááááá. á„áá ááŁááá ááááááá áááá á ááááá á„áá ááŁááá áá ááá„áᥠáááĄáŹáááá áá áááááá đ.
hard to follow examples, your screen is too small
Yea, I realized that a bit late. In section 3 it gets better since I zoom in a bit and also I zoom in on parts that are important.
you know what you don't deserve???? a dislike. nice video.
Thank you đ
Thanks a lot
You are welcome!