How To Include Files In PHP - Include and Require - Full PHP 8 Tutorial

Поділитися
Вставка
  • Опубліковано 18 жов 2024

КОМЕНТАРІ • 109

  • @henrik9173
    @henrik9173 3 роки тому +25

    Learning something new in every video. These are gems!

  • @lotuslando1994
    @lotuslando1994 Рік тому +10

    That was a very thorough and clear explanation about how to include files. I am learning SO MUCH from each video. 👍👍
    I don't think a thousand thank yous would ever be enough to acknowledge all the time and effort that you've put into these training videos.

    • @ProgramWithGio
      @ProgramWithGio  Рік тому

      Very happy to hear that. You're welcome & for me the biggest motivation is exactly this that you & many others are learning & finding my videos useful. So thank you

  • @ouriil
    @ouriil 8 місяців тому +1

    Really there is no other php course like this anywhere online either free or paid..congrats sir professor FOR IN DEEP PRESENTATION OF PHP

  • @mehmetalikaba
    @mehmetalikaba Рік тому +2

    You are the best teacher I have ever seen online! Please upload new videos about other programming languages too.

  • @adoughdough
    @adoughdough Рік тому +1

    Okay now, I must confess this tutorial is really good. The instructor uses succinct and straight-to-point approach to explaining things so the student ends up learning all the way. Gio has no idea how very grateful I am, as in like "ki lo de!" Thank you so very much. I recommend this tutorial for anyone interested in learning PHP.

    • @ProgramWithGio
      @ProgramWithGio  Рік тому +1

      This is awesome to hear, thank you & happy to hear that you are finding these lessons helpful

  • @benderbg
    @benderbg 3 місяці тому

    It takes between 1-2h to chew through 8 min of this video. So much info. This video alone is 5.5 A4 pages with all the code samples. Thanks for great content.

    • @ProgramWithGio
      @ProgramWithGio  3 місяці тому

      Glad it was helpful

    • @lairotuT-Tutorial
      @lairotuT-Tutorial Місяць тому

      Lol, I'm glad to see that there are others that take notes from this course, I felt kinda old style when I started :-) But its soo much info^^

  • @iambasanta
    @iambasanta 3 роки тому +3

    clean explanation. This is the best and legit PHP tutorial ever. Thank you .

  • @Armando-px8hi
    @Armando-px8hi Рік тому

    Actually I was just thinking if there is any other one who is better in PHP than you.The BEST💯🙌👏

    • @ProgramWithGio
      @ProgramWithGio  Рік тому

      There are many that are way better than me, but thank you 🙌

    • @Armando-px8hi
      @Armando-px8hi Рік тому

      @@ProgramWithGio I do not think so🙌👏

  • @gazianis7572
    @gazianis7572 3 роки тому +1

    i am starting to watch your 70 videos more & more times

  • @Vitalii-m6r
    @Vitalii-m6r Рік тому +1

    This lesson helped me a lot. Thanks a million!

  • @nyinyiandnyinyi
    @nyinyiandnyinyi 7 місяців тому

    the best tutorial for beginners.

  • @rakibulhasan8749
    @rakibulhasan8749 Рік тому

    I learned a lot in this tutorial . I didn't know how to assign include file value in a variable and modify the content . Thanks

  • @zoemoorton9570
    @zoemoorton9570 3 роки тому +4

    Thanks! Worked well for me :)

  • @abdelrahmanyosry9185
    @abdelrahmanyosry9185 Рік тому

    i really love this course i never watch some one explain everything about any other language like you. thank you so much

  • @petruciucur
    @petruciucur 2 роки тому

    New and profound things with each lesson.
    What is true (include()) for NAV is also true for HEAD and at the end of the page, for different styles and scripts

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      Hey, sorry for the late reply. Not sure I understand the question. Can you elaborate?

    • @lairotuT-Tutorial
      @lairotuT-Tutorial Місяць тому

      @@ProgramWithGio I guess that comment was just to add to your teaching that not only a nav-file can be extracted and included but head-file and footer-file as well. Of course EVERY file can be added.

  • @prajwalsiwakoti9866
    @prajwalsiwakoti9866 2 роки тому

    Excellent. Man, i am loving it . God bless you Gio

  • @ilya_123__
    @ilya_123__ Рік тому

    i finally have understood the difference between include and require )

  • @oghenevwefepeace2501
    @oghenevwefepeace2501 2 роки тому

    You are awesome. God bless you. I keep learning more and more after each video

  • @lairotuT-Tutorial
    @lairotuT-Tutorial Місяць тому

    Always a pleasure to have these deep dives into the elements of PHP! Best tutor Gio!
    In the beginning require and include kinda confused me (I'm often confused, am I? 🧐)
    A small point I missed and that could be helpful is the mixture of require, include and require_once, include_once. I guess its often result from copy pasting of other peoples code. In only few cases it really makes sense but often it makes no problems. Thats possibly why people stick with it. Maybe I'm too old but I like when (especially if you have many options - and PHP could have the title "many options language") you program by reason and not random.
    Am I right when I assume that always using require_once could be a good strategy and only when your code either shows "I need it a second time" and/or "Its nice to have it, but its not strictly required" switch to one of the other options? I do something similar with "private" and "protected"/"public" later on in Objects.

    • @ProgramWithGio
      @ProgramWithGio  Місяць тому

      Yup, I also use require_once most of the time

  • @amgedalaa1831
    @amgedalaa1831 2 роки тому

    thank you're really a great person, i got complicated from PHP output control functions because i searched for it after you used it in the video and i couldn't understand somethings it was complicated so i wish you will upload a video for it soon 😅

  • @derry_yeh
    @derry_yeh 3 роки тому

    these videos are legit. Brilliant stuff

  • @emekatimothyiloba699
    @emekatimothyiloba699 Рік тому

    Great Tutorial

  • @ballpen9157
    @ballpen9157 Рік тому

    great video. thank you.

  • @ziadsraya
    @ziadsraya 4 місяці тому

    Thank you so much

  • @sreneilif
    @sreneilif 9 місяців тому

    Hi Gio - One question to include and require - when I do 2 include/requirelines like this
    include_once 'includes/layout.inc.php';
    include_once 'Classes/Database.php';
    the top of my page (the first line gets empty and Nav bar in my else working bootstrap theme get pushed downwards... if I add 3 include/require et moves down 2 empty lines. I thought it would be a good idea to include from different files, depending of what I need, like in my example one file for database and one for layout... Question: is it my bootstrap that messes up or isn't it possible to include different pages? I tried with all 4 include/require functions.
    Love your lessons, though they are very fast - good we can rewind and push pause!!!

    • @ProgramWithGio
      @ProgramWithGio  8 місяців тому

      Most likely related to content/whitespace within your layout & other php files being included. I would need to see your setup to be able to help

  • @ilya_123__
    @ilya_123__ Рік тому

    thank you!

  • @p3tmalu1235
    @p3tmalu1235 Рік тому

    Damn, this is a gem. thank you My Dear Sir...

  • @jessieren6476
    @jessieren6476 3 роки тому

    Learning a new tip today : . Thank you sir

  • @anilgajiev8257
    @anilgajiev8257 3 роки тому

    გიო, გაიხარე! Including/rendering a separate component dynamically is much easier with php that with ejs. Nice one.

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому +1

      Thank you 🙌 მადლობა

    • @GeneraluStelaru
      @GeneraluStelaru Рік тому

      It's even easier in Svelte or any other JS framework for that matter. I haven't delved too much into PHP but if that's how it handles dynamic page generation, then it should be relegated to backend logic only.

  • @yarik83men51
    @yarik83men51 3 роки тому

    Like You lessons. Thnx

  • @CarlosOrtiz-sz2pp
    @CarlosOrtiz-sz2pp 2 роки тому

    Thank you

  • @RedBaron19180
    @RedBaron19180 Рік тому

    this is the best php tutorial i have ever seen thank you for everything gio (by any chance are you georgian? :d)

    • @ProgramWithGio
      @ProgramWithGio  Рік тому

      Thank you 💙 and yes I'm Georgian 🙂

    • @RedBaron19180
      @RedBaron19180 Рік тому +1

      @@ProgramWithGio shemogevle gio seriozulad karg videoebs deb mitumetes dzalian momwons patara detalebzec rom laparakob romelsac sxvagan yuradgebas ar utmoben.warmatebebi da kidev ertxel didi madloba am umagresi videoebistvis ❤️

    • @ProgramWithGio
      @ProgramWithGio  Рік тому +1

      @@RedBaron19180 გაიხარე, მიხარია რომ ქართველებიც უყურებენ ჩემ ვიდეოებს 🙌🙏

    • @RedBaron19180
      @RedBaron19180 Рік тому +1

      @@ProgramWithGio aucileblad yvelas shevtavazeb am videoebis yurebas da movematebit :D

    • @ProgramWithGio
      @ProgramWithGio  Рік тому

      @@RedBaron19180 🙏🙏

  • @mimoh2000
    @mimoh2000 2 роки тому

    Really nice tutorial. My question is on the str_replace(). Notice it's also changed the url from 'about.php' to 'About Us.php', which the give 'file not found' error. Any work around solution to this. Once more, thanks.

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      str_replace is case sensitive as far as I remember so it should only replace 'About' with 'About Us' it wouldnt replace 'about' lower case version. Try it out.

    • @mimoh2000
      @mimoh2000 2 роки тому

      @@ProgramWithGio yes absolutely correct. The str_replace() is case sensitive. Replacing 'about' with 'About us' always changes the URL. The first parameter is case sensitive. From what I understand the str_replace() takes 3 parameters. First, the string you want to be replaced. Second, the required string and third, the variable that holds the string. In whichever way, it always changes the URL.

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      @@mimoh2000 I just tried it: 3v4l.org/8K4oM and it works as expected, maybe I'm missing something?

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      Here is the snippet with the exact nav: 3v4l.org/13noQ
      as you can see in the result it does not update the url.

  • @patel5532
    @patel5532 2 роки тому

    Great tutorial as always. Could you explain how str_replace() function change the content and what if file has multiple similar name then how str_replace() function work?

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      str_replace just replaces all occurrences of the search term with whatever you give it. There are more examples here: www.php.net/str_replace

  • @aweisabdi6947
    @aweisabdi6947 3 роки тому

    you helped me thnks sir

  • @aswadali5139
    @aswadali5139 2 роки тому +2

    If you are going to learn PHP in 2022, This course is for you.

  • @MobiusCoin
    @MobiusCoin Рік тому

    Did we cover ob_ stuff in detail yet? I feel like I'm missing something.

    • @ProgramWithGio
      @ProgramWithGio  Рік тому

      Do you have any specific question about it? We do use it again later in the course when we get to views

  • @rxxt-sh1vj
    @rxxt-sh1vj 2 роки тому

    Bro as stated in last example If i take contents of a php file and inject it inside HTML file against a placeholder {{content}} inside body tag using the functions ob_start( ) and ob_get_clean( ) as you showed in the video in the last
    this is my practice.php file
    --------------------------------------------------
    $x = 5;
    function foo(): void
    {
    global $x;
    echo "Hello $x";
    }
    foo(); Expected output -- Hello 5
    Getting the output as --Hello
    In the output I loose 5 .Does using a function as a string and injecting it in the layout makes it loose content in case of Global Scope? In rest of the cases I am getting expected output. Need your suggestion

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +1

      Never use global, its not a good practice, most likely whats happening is that global $x is redefining variable without value.

    • @rxxt-sh1vj
      @rxxt-sh1vj 2 роки тому +2

      @@ProgramWithGio I am practicing your entire PHP course video by video so this is the same example as you gave in video 1.23...:D Anyways I am in love with your PHP video series it has improved my knowledge a lot and has made me learn a lot more concepts...even some things I had never seen anywhere or heard of...Also shows exceptional effort you have put in your videos for including all sorts of content...:D

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +1

      @@rxxt-sh1vj ah didn't realize you were using my example. In that video I was just showing it to illustrate an example, globals shouldn't be used in modern PHP, it's good to know what it is and how it works in case you are working on a legacy codebase.
      Thanks alot, I'm really glad that you like my videos.

  • @godmansarah
    @godmansarah 2 роки тому

    This is great, although maybe your `require_once` demo would be even more effective if you had kept the first call as `require`.

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      Thank you 🙌. It would have the same effect.

    • @godmansarah
      @godmansarah 2 роки тому

      @@ProgramWithGio Yes exactly - some people though might think that you need to put it on all require calls for it to work, not just those after the first call. 🙂

  • @IonizedComa
    @IonizedComa 5 місяців тому

    Its amazing how php has default functionality when other languages like js and python would need entire frameworks to do this

    • @ProgramWithGio
      @ProgramWithGio  5 місяців тому

      Yea PHP is amazing & once you get to full stack frameworks like Laravel you'd be amazed how much functionality comes in built in

  • @subish20me
    @subish20me 2 роки тому

    when using require two times in a same file i got redeclare error but didnt got it with require_once... but theres no error in ur side what might be the reason

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      require_once only includes it once, but with require, it would cause the error if you had a function in the file for example. If you are referring to the example at 2:15 there it's just an echo statement so nothing is being re-declared, if I had function, for example, it would cause an error.

  • @Vickey51193
    @Vickey51193 8 місяців тому

    Awesome video but "Don't worry about this now"---

    • @ProgramWithGio
      @ProgramWithGio  8 місяців тому

      Yes because we cover it later in the series.

  • @NirajDhakal
    @NirajDhakal 2 роки тому

    This is where @blade directives can be parsed

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому

      Yes but we are not working with Laravel or blade

  • @illegalsmirf
    @illegalsmirf 2 роки тому

    You didn't say anything about goto statements 😞

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +2

      That was the point 😁. You don't need to know it, don't use it.

    • @illegalsmirf
      @illegalsmirf 2 роки тому +1

      @@ProgramWithGio hahaha that’s good 😸

  • @prabu2778
    @prabu2778 3 роки тому

    Thanks sir
    Where are you from sir

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому +3

      You're welcome. I live in the U.S. but originally from country Georgia

    • @prabu2778
      @prabu2778 3 роки тому

      @@ProgramWithGio I am very happy to get reply from you
      Thanks for your support

    • @ProgramWithGio
      @ProgramWithGio  3 роки тому

      @@prabu2778 You're welcome, thank you for the support as well

  • @arturlinnik2128
    @arturlinnik2128 7 місяців тому

    Wait wait wait, are you really saying that if I include a php file into another I automatically have access to the variables and functions and that it can also overwrite the variables I have declared in my original file? What kind of dumb implementation is this? Wtf php??? Am I missing something??

    • @ProgramWithGio
      @ProgramWithGio  6 місяців тому

      Yes that can be considered a good or bad depending on how you look at it. It comes in handy for templating engine implementations & there are some other use cases but in general yes it can be tricky to work with which is why I avoid having variables defined in files that are being included in other files. Once you start using OOP & proper templating this shouldn't be a concern

  • @christiansosa5484
    @christiansosa5484 Рік тому

    xD