Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

PHP

Name: Anonymous 2010-06-01 2:49

I had no idea I had a course in PHP this semester, evidently I do and the exam is tomorrow. I need to learn PHP in 18 hours and complete an assignment before the test. Teach me PHP!

Name: Anonymous 2010-06-01 6:24

>>8
PHP's documentation is quite good. A reference to the language is at http://www.php.net/manual/en/langref.php

Some quick points:

Free-form with {} and ; like C, except that the code itself is inside <?php and ?>. Everything else is printed, though you can mix it with control structures, i.e. if ($doit) { echo "hi"; } is equivalent to if ($doit) { ?>hi<?php }

Arrays, integers, floats and booleans are not objects. One calls functions on the instead like in C.

Arrays are both lists and dictionaries. array("a","b","c"); is equal to array(0=>"a", 1=>"b", 2=>"c");

Horrible duck typing. When cast to a boolean, array(), "", "0", 0.0, and 0 all evaluate to false. When cast to an integer, "", "alpha", and "0" all evaluate to 0. Strings cast to an integer uses the part matching ([0-9]+) and discards the rest. Objects cast to an array get their property names as keys.

When variables are referenced before assignment they are assumed to be NULL (equivalent of python None) and an E_NOTICE-level error is emitted and execution continued.

Strings, etc. are not immutable.

Variables are not references to objects unless explicitly set as such with $a = &$b;. Though, arrays and such are copy-on-write, so $new = $xbox_hueg_array; doesn't necessarily copy the whole thing.

>>12
No. The first argument to ereg_replace is a regular expression. You shouldn't be using that anyway for straight replacements:


<?php
function make_page($name, $head, $body, $tmpl = "base_page.html", $navi = "base_navi.dat") {
        $page = file_get_contents($tmpl); // page = open(tmpl).read()
        $page = str_replace("[navi]", $navi, $page); //page =  page.replace("[navi]", navi)
        $page = str_replace("[head]", $head, $page);
        $page = str_replace("[name]", $name, $page);
        $page = str_replace("[body]", $body, $page);
        echo $page; // print page
}


print() is a function and echo is a statement. echo is slightly faster and considered better practice.

assuming you use Windows, get a WAMP-stack or something: http://en.wikipedia.org/wiki/Comparison_of_WAMPs

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List