Help - Search - Members - Calendar
Full Version: PHP Tutorial
W3Schools Forum > W3Schools > Suggestions
kaijim
Hello everybody!

We are currently trying to make the PHP part of the page better.

We have taken a small break from writing the reference part (have made over 400 reference pages the last months), and we have started working on the tutorial part.

I would very much like to get suggestions on what to add smile.gif
boen_robot
A thing I certanly want to see is global variables handling, such as the GET variable. You know, the ones with which when you type "?VariableName=VariableValue" at the end of the URL to trigger special actions in the PHP file.

Maybe some more detailed information on form processing and an example of simple MySQL connection and action (just like the ODBC example).

And one thing which is probably with the least prirority but... some kind of universal way to install extensions? I mean... most extension's installation follow similar steps, right? If so, what are they? The one of my particular interest is (as some people of this forum could already figure out) a step-by-step way to install the XSLT Processor extension.
Chocolate570
I'd love more on SQL connections like boen said, and we need a detailed tutorial on classes. They're pretty important.

Maybe some examples on how PHP can interact with AJAX and perform different things too.

Sessions would be nice, along with (slightly off-topic) a PHP quiz? I've always wanted to check how much I can do tongue.gif (which shouldn't be much) smile.gif

I'll see if I can come up with some other things...

I suggest you just look at the ASP section and try to balance each one out. smile.gif
Jonas
An example of an email form, because that is the question that is most often asked here...
boen_robot
QUOTE (Jonas @ Apr 26 2006, 04:22 PM)
An example of an email form, because that is the question that is most often asked here...
*

What about the one here? I haven't tested it, but it seems as a PHP email form to me.

[edit]@...678 what are you talking about? What you show is BBCode. It doesn't belong anywhere in the PHP tutorial. [/edit]
...678
i think it should have the basics like [B] [I] [U] [URL] etc.
aspnetguy
QUOTE (...678 @ Apr 26 2006, 10:54 AM)
i think it should have the basics like [B] [I] [U] [URL] etc.
*


BBCode only exists in this forum (and other forum software). It is not even a language. It is just a way to format posts in a forum.

It was a way to allow post formatting without allowing full html coding.
Jonas
QUOTE
It was a way to allow post formatting without allowing full html coding.

String replacement, right?
kaijim
The e-mail form was added yesterday.. so that is brand new... just a simple way to send mail... i am planning to add more examples.. and a guide to avoid spammers getting your mail adress..
aspnetguy
QUOTE (Jonas @ Apr 26 2006, 02:49 PM)
String replacement, right?
*


Yeah that is all IPB does. It uses string replacement to add the proper HTML when it finds a BBCode.
Jonas
Well, then I guess one php example would be string replacement, for a guestbook or forum, with example of how to detect bbcode sets, split it into three (opentag, data to format, endtag) and replace the opentag and endtag with < and > instead of [ and ].
Jack McKalling
I don't know if it is an old idea or a new one, but is it possible to create a Try-it editor for PHP?

Maybe eval() could be used for that, like eval($_POST['php_input']);
Of cource with limitations smile.gif
boen_robot
Nah, that's a really high security risk. More like live example, such as the code on the left and the result on the right WITHOUT the ability to edit the code (like in the ASP tutorials).

I think it would be good if something like an example on how to use regular expressions is shown. But perhaps the already suggested regular expressions tutorial would have to be created first though.
Jack McKalling
Such examples would do the trick too wink.gif
There is always a security risk when php gets allowed in editors, but maybe it would be just cool when only the ECHO instruction was allowed happy.gif

Beginners playing such as echo "I have hacked yor site!!"; biggrin.gif
Jonas
Yeah, I don't think a php editor could be more advanced than this. They could even make examples in php, while the file name was still .asp, since the code they output doesn't do anything. That way, they wouldn't need a php server...
MISIIM
BBCode can be done like this:
CODE
<?php

$code = preg_replace("\[b\](.*?)\[\/b\]","<b>$1</b>", $code);

?>
Little Goat
yes, but it would be nice if that could be in the tutorial for noobs (like me!) so they don't have to come here and ask.
reportingsjr
could you put in the foreach() loop? cant miss anything..
scott100
Maybe a mention for a program like EASYPHP which includes PHP, Apache and MySQL.

It can be a very daunting task for newcomers to get these 3 up and running, when you can just instal a program that does all this for you cool.gif
Jonas
http://www.apachefriends.org/en/xampp.html

xampp is great for installing... smile.gif
deved
I'm a newbie PHP student and see a lot of sites that require logins to access information companies have about individuals such as, ISP's, banks, hosting providors, etc.

On your 'web building' page for developers under the Server Side Scripting section, you mention 'Provide security and access control to different Web pages'

Could a tutorial be done on this? smile.gif
Yuval200
Here are some things that by my opinion, would make the php tutorial better:
  1. Here, under the section "Comments in PHP", you forgot to mention that you can use "#" too, like:
    CODE
    <?php
    \*Comment!
    another omment!*\

    echo "I like ";   //prints "I like "
    echo "pasta!"      #prints "pasta!"
    ?>
  2. Try to explain more about how to install PHP, Apache and MySQL.
  3. Try to make a page with information about programs that install the three servises, like EasyPHP or WAMP.

Offtopic: a CSS tutorial about designing scrollbars would be nice smile.gif (so far I didn't found one, I might missed it if you have one)
Jonas
There's no need of a tutorial for css scrollbars, because Scrollbar-css is not a part of any css spesification, be it 1, 2.1 or 3. Scrollbar-css is microsoft only css.
dcole.ath.cx
With FireFox you don't need to edit the scroll bar to look like the webpage, I want the scroll bar to look like my browser... The scroll bar would really fit into the browser owned more than the webpage owned...

not to make a argument or nothing..
joecoolaug
Well I think that the best thing to add would be detailed explainations of every bit of code. I've noticed that some of the PHP tutorial pages and many others don't explain certain bits of code at all or not enough.
SirPaladin
Perhaps practical projects, BBCode like it`s been mentioned, how to code finite data trees (for forums, for example), paging etc.. It`d be very interesting. Although you could just stick to theory and add a detailed OOP page. smile.gif
boen_robot
I think a fine addition to the PHP tutorial that would be good, without going too much spoonfeeding on the user, if it includes the regular expression functions.

Now that theese functions are used in the Secure Mail script, such explanation is more requred then before. Not to mention regular expression functions are used in a lot of other scripts, such as the above mentioned BBCode for example.
Mwnci
How about some more advanced features of PHP? For example sockets and how to use exec...

Also how about a page of challenges to test your php ability? smile.gif
eguru
can add some examples for php too.
Jorn van Engelen
This PHP tutorial was very usefull.
The only thing I couldn't find was how to put an [enter] in a file. dry.gif
I found the awnser of this question 2 weks ago. biggrin.gif
Just write

fwrite($file,"\r\n");

in your PHP file.
I think this is very usefull for people who want to make a database without using mySQL.
reportingsjr
Hmm, the carriage return (\r) and newline (\n)? Are you sure? And I dont think you need the return, just the \n FYI wink.gif.
justsomeguy
It depends on the OS. DOS format is CRLF, Unix-based systems prefer LF only, and Mac-based systems prefer CR only.

btw:
LF = line feed = \n
CR = carriage return = \r

A Linux system seeing \r\n will sometimes show 2 newlines. But, for things like email headers, \r\n is required by the RFC to separate them, even though just \n is used in the email body.
sree06
hi,
PHP tutorial is nice ....
adding to the above disc v can have something rel to ADO connectivity thru PHP - which is very useful 4 many appln proging ....
then something covering PEAR packages ....
shopping cart integrations ....
last but not the least something rel to CMS tools ...
justsomeguy
Specific applications like shopping carts and CMS programs typically don't have tutorials. You pretty much have to design it, break it down into features that you want and then figure out how to make each feature work individually.
Mosquito
Personally, I would like to see a section added about PHP Image manipulation and the GD library and such. It wouldn't have to be a very in-depth tutorial, basically one just to let people know what they can do. But a full PHP Image reference would be useful.
Anders Moen
Yeah, but you can also go to www.php.net/gd wink.gif
Mosquito
QUOTE (Anders Moen @ May 9 2007, 12:54 AM) *
Yeah, but you can also go to www.php.net/gd wink.gif


Yes, you could also go to PHP.net for examples of every other item on W3S. I think that some of the missions of W3S is to simplify concepts for beginner developers, as well as provide comprehensive references to the more advanced. A PHP GD section deserves a spot I think.
Necrotising Fasciitis
One very simple and easy to set up Server Package is AppServ. It is available from http://www.appservnetwork.com/. It includes PHP, MySQL and Apache and will run on any windows computer. Took me five minutes to install and have my server running nicely. biggrin.gif
Xalor
We should have something that deals with CMS with the PHP, I don't see anything that makes PHP work with SQL in there. Thats important for game designers, who plan to host their game online, or private servers for games like MapleStory, who need a database system for their website.
Deirdre's Dad
QUOTE (Xalor @ Sep 22 2008, 01:45 PM) *
I don't see anything that makes PHP work with SQL in there.


http://www.w3schools.com/php/php_mysql_intro.asp
shadowblade
Something that needs to be fixed right away...
On the file upload section (http://w3schools.com/php/php_file_upload.asp) the file_exists() function is called, but the value passed to it is the user's file name, so with the given setup, the script will always stop because the file that the user selected to upload does in fact exist.
This can be fixed like so...

CODE
<?php
$userfile = $_FILE['formfile']['name'];
$name = basename($userfile);
$dir = "some_upload_directory/";

if (file_exists($dir.$name))
//code
?>


On that note, a few other things I'd like to see in the file upload section are a reference of MIME types for common files (and the fact that $_FILE["file"]["type"] is a MIME type and not just a common extension - afaik this isn't mentioned anywhere).

Also, I don't think it is mentioned ever that the "file" in $_FILE["file"] is the name of the file field in the form. I can see this being very confusing for a beginner. It should be changed to something to differentiate it from the $_FILE array.
Jack McKalling
QUOTE (shadowblade @ Sep 25 2008, 07:17 PM) *
...
On that note, a few other things I'd like to see in the file upload section are a reference of MIME types for common files (and the fact that $_FILE["file"]["type"] is a MIME type and not just a common extension - afaik this isn't mentioned anywhere).
...


Actually there is a MIME-types list on W3Schools. Just not in that tutorial smile.gif
See this list: http://www.w3schools.com/media/media_mimeref.asp (Media Tutorial)

You're right about the "file" name of the file-input, indeed confusing. I would choose "userfile" or so.
jlhaslip
On that list, I could not find application/x-httpd-php or application/x-httpd-phps ???

*edit*
I forgot to RTFM.
"The reference below is a list of MIME types supported by Microsoft Internet Information Server version 5."
M$ uses ASP don't they?
justsomeguy
You can install PHP on IIS as well, in fact every server I've installed PHP on was IIS.

I don't really think that w3schools has a "complete" list of anything though.
Synook
There can never really be a complete list of MIME types - for example, a new one could be invented for appml: application/appml+xml, and as long as the required agents understand, it is fine.

IIS don't call their server a HTTPD though, so it may have a different MIME type for PHP documents.
justsomeguy
The IIS that I'm looking at doesn't even have a mime type set up for PHP. That would make sense, because it's not sending the PHP files for download. There is an application mapping for PHP files, but not a mime type. If I wanted the server to send the files instead of execute them I could remove the application mapping and add a mime type.
{No}-{Name}-{At}-{All}
Sorry, but there is no way I'm going to read through all those replies, I just want to say that PHP need the 'try it yourself' links.
justsomeguy
Not going to happen. It would be an enormous security threat to allow people to enter arbitrary server-side code for the server to execute. That goes for both PHP and ASP. There's no try-it editor for ASP code, either. Only client-side code. If you want to execute server-side code you need your own server (or space on someone else's). If you want to set up your own site to allow people to execute their own PHP code, fine, but don't expect your server to stay online very long.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.