Treehouse: Grow your CSS skills. Land your dream job.

Starting PHP

  • # March 3, 2012 at 11:01 pm

    So I’m interested in starting PHP. I want a base index.php with references on how to link to a header.php file ans so on. I also want to know the markup for a linked PHP file. Does it need a whole head and body tag, or does it just need the div element with < ?php> or whatever it is.

    Thank you.

    # March 3, 2012 at 11:50 pm

    Have you tried doing any research at all? A simple google search throws this little tid bit up…

    should get you going on absolute for dummies level stuff.

    # March 4, 2012 at 12:05 am

    Have you checked out WordPress?

    # March 4, 2012 at 12:54 am

    @kgscott284 That answered none of my questions.

    @nlfatkid I knew that WordPress worked on PHP, but I wanted to understand PHP so I could start, hence, why I’m asking. I could Google it, but I understand better when people on the forums tell me. Sometimes not, but most of the time.

    # March 4, 2012 at 1:04 am

    I gotchya… I’m still kinda figuring out PHP myself… I don’t have a good grasp on it either. It feels a lot like high school algebra to me. “If, then” statements still don’t always make sense to me and it seems like the verbage of PHP doesn’t always make sense.
    The thing that helped me understand PHP the most was WP. Have you looked at how a theme works?
    The construction of it?
    PHP works pretty damn close to it. I’ve always understand that the WP codex is a copy cat version of PHP. I just went through a huge battle with a guy on StackExchange, all over semantics of a PHP “loop” and the WP “Loop”.

    # March 4, 2012 at 3:16 am

    I agree with @kgscott284 — you’ll be better off learning things yourself than when people give you ready-to-use code. If you want to learn a new language, learn to walk before you jog.

    But right.

    To link a header in your index.php file:

    < ?php include 'header.php'; ?>

    The contents of header.php will simply be placed where you call the include, so no additional header/footer/etc. needed.

    More info:

    Go get ’em!

    # March 4, 2012 at 4:21 am

    I assume you didn’t look or google at all…?

    The link i provided in fact answers one of your questions directly, it even provides a solid example noted in the code below.

    < ?php echo '

    Hello World'; ?>

    The main idea is you can pretty much use any standard .html page and save it as a .php, then the server will recognize it as such. You may then include files, using php code, either a include or require depending…or use php code (as in the example provided.)

    # March 4, 2012 at 5:55 am

    I would say go through this video series and you will be ready to make real things quickly.

    # March 4, 2012 at 7:18 am

    Hey Odd_E,
    There is no one right answer for this, the best thing to do is familiarize yourself with PHP before decided what style you’d like to code in

    I do have a relevant tip though
    If you include a php file open it with < ?php but don't close it, any trailing lines or spaces after ?> may cause errors, whereas leaving it open won’t

    These two YouTube channels are great for beginners right up to advanced


    # March 5, 2012 at 10:26 am

    Also, is always a good resource.

    # March 5, 2012 at 11:10 am

    @knittingfrenzy18 — I respectfully disagree. See :)

    # March 5, 2012 at 12:19 pm

    I’ve used this site a lot: They have very good tutorials for most problems a beginner is going to have.

    # March 6, 2012 at 1:28 am

    I’ve seen the W3Fools thing before. I haven’t used W3 schools in a few months.

    # March 7, 2012 at 9:55 am

    Senff and Odd_E, I do agree w3schools is quite inaccurate–I have seen the w3fools before. However, in most cases, it provides a build-off platform-I learned the very basics there and then built off by googling other sites like this one.

    I find it to be useful when I forget syntax or a function, but I do agree it is quite inaccurate.

    # March 7, 2012 at 10:02 am

    @knittingfrenzy18 You’re right, it can be helpful when it comes to the super bare basics. If I need something fairly simple (things like the basic syntax of a CASE statement in whatever language) and I google it, I often end up on W3Schools. So yea, I use it for quick reference every now and then, but I wouldn’t recommend it to anyone as a starting course.

Viewing 15 posts - 1 through 15 (of 18 total)

You must be logged in to reply to this topic.