RE: [ILUG] developerWorks article...

From: adam beecher (adam at domain iewebs.com)
Date: Sun 14 May 2000 - 20:12:52 IST


> http://www-4.ibm.com/software/developer/library/script-survey/
>
> while it's focusing on cgi a lot is applicable to everyday stuff. note
> at the bottom that there are some links to other scripting tutorials
> including two on bash.
>

Very interesting, although he obviously hasn't looked into PHP very heavily...

<QUOTE>
Task 2: Put form field data into variables

PHP and Java servlets let you skip the first step and jump right to assignment,
as long as you get the variable names you expect. For more generic processing,
you would iterate through the list of received variables and assign them
dynamically.

$data = $HTTP_POST_VARS["data"];
$data2 = $HTTP_POST_VARS["data2"];
</QUOTE>

Eaaagh! Wrong! PHP lets you skip all steps - all GET, POST and ENV variables are
imported to the symbol table automatically at runtime. So if you pass a variable
via GET in a URL <http://www.dom.com/script.php3?var1=val1>, 'val1' is
immediately available in $var1. Same goes for environment variables -
$HTTP_HOST, $REQUEST_URI, etc. It's one of the best things about PHP.

</QUOTE>
Task 6: Split comma-delimited line into variables

        list( $a,$b,$c,$d ) = split( ",", $last, 4 );
</QUOTE>

In this case, he's right, but he's wasting resources - explode() would be a
better function to use here, because it splits on a plain-jane string. split(),
however, splits on a regex, meaning it has to load up the regular expression
engine.

It's all in the manual. RTFM Mr. McElwee. :)

adam



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:06:08 GMT