PHP Dr. Steven Bitner
Your UMKC PHP account http://kc-sce-sphp01.kc.umkc.edu/~SSO SSO is your UMKC username, e.g. bitners Use an SSH program such as PuTTY to create code Alternatively, you can write code on your local machine and upload with Filezilla or other SFTP clients
Connecting in PuTTY Machine name: kc-sce-sphp01.kc.umkc.edu Use default port of 22 Connection type: SSH (default) Enter SSO as username and standard school password as password
Linux ls lists files in the current directory cd DIRNAME changes to the directory DIRNAME vi FILENAME opens FILENAME for editing using vim rm FILENAME deletes FILENAME There is no ‘recycle bin’ in Linux mv FILENAME NEW_FILENAME moves a file from one location to another
Vi How it functions is controlled by ~/.vimrc Save - :w Quit - :q Find a string - /string or ?string Find next occurrence of current string - * Auto-complete – ctrl+n or ctrl+p Vim is the most powerful text editor you will ever use Steep learning curve
What is PHP? Stands for PHP Hypertext Preprocessor C-like server side scripting language Designed for the web
PHP.net Strong community support base With that comes good and bad code Can be difficult to tell the difference between what worked and what is a ‘best practice’ All standard PHP functions and example code
Why use PHP? Very fast Easy database interoperability Free Easy to learn and use It’s what you’ll be tested and graded on You can accomplish just about anything with it
Variables Do not need to declare variables Prefix all variables with a dollar sign $myVariable = ‘CS /IT 490 WD’; PHP can also use variable variables, we’ll discuss this more toward the end of the semester $name = ‘Steven’; $Steven = ‘A really cool guy’; echo $$name; // outputs ‘A really cool guy’
Loose typing $groceries = ‘4 bags’; // assigned a string value $groceries++; echo $groceries; // ouputs 5
Comparison operators Like javascript === is not the same as == if (strpos (‘Hello’,’He’)) { }
echo How to output text (this is what makes html pages) Can also use print, but it is a slower operation
print_r ( ) and var_dump ( ) Used in debugging Outputs all contents of arrays
Heredoc echo <<< ENDHTML lots of output here ENDHTML;
Strings Can enclose strings in ‘’ or “” ‘’ does not interpret $myVariable = ‘ Booyah ’; echo ‘Value: $ myVariable ’; outputs Value: $myVariable echo “Value: $ myVariable ”; outputs Value: Booyah
Concatonation use the . echo “Hello” . “class”; $myVariable = ‘I can \ ’t believe it is already ‘; $month = ‘September’; $text = $myVariable; $text .= $month;
Variables in strings Variable names will not work correctly when they are adjacent to any character that is a valid part of a variable name echo “My value is $ myVariableand there is nothing you can do about it”; echo “My value is ${ myVariable}and there is nothing you can do about it”;
Recommend
More recommend