Jump to content

[SOLVED] Most important PHP functions to learn in 3 hours


Recommended Posts

Hello,

 

I am seking feedback. I am going to be providing a one time class to PHP newbies. My goal is to go from NO knowledge to a first script and make it useful and set the spark for futher learning with PHP.

 

Your fedback to any one of the folowing:

 

1. What were the most important functions to you in starting with PHP?

 

2. What did your first script have to accomplish?

 

3. What would you want a newbie to know?

 

 

Thanks! and if I should move this to a different forum, please advise.

 

Richard

 

I will mark this post "SOLVED" within 48 hours

Thanks for the siteppoint link, I will add it to me resources handout.

 

I was just hoping to get feedback suggestive of actual usage.

 

Writing the class  with examples will still be the fun part. I just want to make the most of limited time.

 

 

Should I pull this thread or is there a better forum for this?

 

Richard

1. Quick rundown of apache/php5/mysql installation/configuration

I don't think it's that important... most newbies use a remote host somewhere, not run their own server. And for development/testing, there's XAMPP which works out of the box. Besides, there's no way you would do this topic justice in three hours.

 

www.w3schools.com they have loads of languages there, that's where I learned it from ;)

Haha! Me too... w3schools is great. I still go there all the time for HTML and CSS reference.

 

My notes:

I would go over the general language syntax, spend a bit of time on variable types, casting, etc. and then do a couple examples. Maybe  how to send an email from a form. Or how to deal with a file upload.

 

But I would leave at least a bit of time at the end to tell them some of the things PHP can do, but not how to do it. Smart people can google it, the most important thing is to know if something is possible or not. I'm thinking just briefly mention things like GD image lib, ezPDF lib, writing text/excel/whatever files from PHP, making a secure login area w/$_SESSION, search scripts, etc.

 

Finally, make sure you point them to the following websites:

1) THIS WEBSITE: http://www.phpfreaks.com/forums/

2) http://www.php.net -- Lots of stuff here, I use it mainly for the PHP function reference.

3) http://www.w3schools.com -- help for every web programming language you can think of.

4) http://sourceforge.net -- every time you think of a more complicated task/project, look here; it may have been done before. Use their search function and put "PHP" in your query.

5) Last but not least: http://www.google.com for solving almost any problem you ever have.

 

Ack, this got long. Sry. ;)

Keep it simple to begin with...

 

I would simply go through that site point article.

 

Get them to interact with data transferred to and from pages, and interact with the database.

 

That will be more than enough for a starters class.

 

By all means get into the nuts and bolts in subsequent classes bt diving in and doing an emailer while fun is not really going to let them grasp the fundamentals without distracting them - they will be foxused on the actual email rather than the data interaction IMO.

 

Teaching the ins and outs of the functions and constructs of php should come later on...

I learned php the hard way, I was tossed into the deep side, I had two choices, either swim or sink.

 

You're question with my answers:

 

1. What were the most important functions to you in starting with PHP?

The session super global.

 

2. What did your first script have to accomplish?

Be able to work after modifications.

 

3. What would you want a newbie to know?

String's, learn it, We all still get people who asks these basic things.

Read, http://php.net/string

I would teach them to use echo instead of print.

 

Echo is better than print. It does the same thing while it can do a bit more. Not sure exactly what but that is what I read.

 

You should teach them that php is server side language and compare it to javascript. Tell them a bit of history of it. LIke a quick two minute summarty.

 

<?php ?>

 

Then tell them how to save it on notepad as a .php file and put it up on server and test it.

 

tell them the php fundamentals. Like echo and if else statments. These are not functions but built in key elements of php.

 

Php-info () is important.

 

isset ()

session_start ()

YOu can do a session example how to handle variables. When I first learned it I thought that was awesome!!

 

 

Echo is better than print. It does the same thing while it can do a bit more. Not sure exactly what but that is what I read.

 

Here is a thorough description of print vs. echo, although I wouldn't say that echo can do more than print. They have their pros and cons, and there are situations where you would prefer one over the other.

You can use echo without surrounding stuff in (), thus saving time coding and disk space and a lil bit of CPU.

"Print" is longer then "echo" thus takes longer to type and more disk space.

Print (pointlessly) returns true, thus making print slower, where as echo just outposts the text.

"Echo" sounds more cool and unique then "print", and rolls off the tongue better.

 

Sure you can argue that the benefits aren't huge, but that doesn't change the fact.

 

Is there any benefit to using print instead of echo?

print() behaves like a function in that

you can do:  $ret = print "Hello World";And $ret will be 1That means

that print can be used as part of a more complex expression where echo

cannot

I could have sworn that I used $a=echo'Some text'; before and it worked..

Is there any benefit to using print instead of echo?

 

Very simple conditional message output. I've used this in a few situations, usually for error messages.

 

<?php

// If some message hasn't already been displayed, then show it. If it hasn't, then don't show it.
$displayed = $displayed ? $displayed : print("Some message.");

?>

 

You can't do that with echo.

Is there any benefit to using print instead of echo?

 

Very simple conditional message output. I've used this in a few situations, usually for error messages.

 

<?php

// If some message hasn't already been displayed, then show it. If it hasn't, then don't show it.
$displayed = $displayed ? $displayed : print("Some message.");

?>

 

You can't do that with echo.

 

You can, but you need to change it a bit.

 

<?php
echo $displayed ? null : "Some message.";
?>

 

Very simple conditional message output. I've used this in a few situations, usually for error messages.

 

<?php

// If some message hasn't already been displayed, then show it. If it hasn't, then don't show it.
$displayed = $displayed ? $displayed : print("Some message.");

?>

 

You can't do that with echo.

 

You can, but you need to change it a bit.

 

<?php
echo $displayed ? null : "Some message.";
?>

 

Close, but not quite. Now that the message has been displayed, you need to adjust $displayed accordingly. I've used this in situations where I want a particular set of text to be shown once, and where there are multiple triggers. Once the text is shown, you don't want it shown again.

 

How about something like this?

 

<?php
if($variable || print("Some message"))
{
//Execute some code here
}
?>

 

I can see this being useful in situations where you want the code to execute, but you want to show a warning or some other text when the first conditions weren't met.

Ah, I see... print returns true (well, actually it returns int 1, but that'll still evaluate to true) and therefore $displayed will hold the value of true. It will only be printed if $displayed is false. I forgot print returned a value, I can't remember ever having used it.

Now, of course, neither of those situations where you might want to use print's return value are very common, nor are they very advantageous over any other ways of solving the same problem, but they are there. :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.