Semis Lecture 1 Flashcards
___ is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
PHP
PHP is a ___, and a powerful tool for making dynamic and interactive Web pages.
server scripting language
PHP is a widely-used, free, and efficient alternative to competitors such as ___.
Microsoft’s ASP
sample php code block
<html>
<body>
< ?php
echo "My first PHP
script!"; ? >"
</body>
</html>
PHP is an acronym for…
“PHP: Hypertext Preprocessor”
PHP is a widely-used, …
open source scripting language
___ are executed on the server
PHP scripts
PHP is free to ___
download and use
What is a PHP File? PHP files can contain… (5)
text, HTML, CSS, JavaScript, and PHP code
___ are executed on the server, and the result is returned to the browser
as plain HTML
PHP code
PHP files have extension…
“.php”
What Can PHP Do?
* PHP can generate ___
* PHP can ___ on the server
* PHP can collect ___
* PHP can ___ cookies
* PHP can ___ in your database
* PHP can be used to ___
* PHP can ___
dynamic page content;
create, open, read, write, delete, and close files;
form data;
send and receive;
add, delete, modify data;
control user-access;
encrypt data
With PHP you are not limited to ___. You can output (a), (b), and even (c). You can also output any text, such as (d) and (e).
output HTML; (a) images, (b) PDF files, (c) Flash movies, (d) XHTML, (e) XML
Why PHP?
* PHP runs on ___ (Windows, Linux, Unix, Mac OS X, etc.)
various platforms
Why PHP?
* PHP is compatible with ___ (Apache, IIS, etc.)
almost all servers used today
Why PHP?
* PHP supports a ___
wide range of databases
Why PHP?
* PHP is ___. Download it from the official PHP resource: www.php.net
free
Why PHP?
* PHP is ___ and ___ on the server side
easy to learn; runs efficiently
To start using PHP, you can:
* Find a ___ with PHP and MySQL support
* Install a ___ on your own PC, and then install PHP and MySQL
web host; web server
Use a Web Host with PHP Support
* If your server has activated support for PHP…
* Just create some ___, place them in your web directory, and the server will automatically parse them for you.
* You do not need to compile anything or install any extra tools.
* Because PHP is free, most ___ offer PHP support.
* Set Up PHP on Your Own PC
you do not need to do anything;
.php files;
web hosts
However, if your server does not support PHP, you must:
* install a (a)
* install (b)
* install a (c), such as MySQL
(a) web server;
(b) PHP;
(c) database
Basic PHP Syntax
* A ___ can be placed anywhere in the document.
* A PHP script starts with ___ and ends with ___
PHP script; <?php & ?>
sample of basic php syntax
<?php
// PHP code goes
here ?>
Example
<html>
<body>
<h1>My first PHP page</h1>
</body>
</html>
- PHP statements end with a ___
semicolon (;)
A ___ in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be ___ who is looking at the code.
comment; read by someone
Comments can be used to:
* Let others…
understand what you are doing
Comments can be used to:
*
Most programmers have experienced coming back to their own work a year or two later and having to re-figure out what they did. Comments can remind you of what you were thinking when you wrote the code
Remind yourself of what you did
php code snippet with comments example
Example
<html>
<body>
</body>
</html>
Example
<html>
<body>
</body>
</html>
does all those echos work?
yes
In the example below, only the first statement will display the value of the $color variable (this is because $color, $COLOR, and $coLOR are treated as three different
variables):
Example
<html>
<body>
</body>
</html>
when it comes to variables, php is case-sensitive
Data Types: Variables can store data of different types, and different data types can do different things. PHP supports the following data types: (8)
- String
- Integer
- Float (floating point numbers - also called double)
- Boolean
- Array
- Object
- NULL
- Resource
A ___ is a sequence of characters, like “Hello world!”.
string
A ___ can be any text inside quotes. You can use single or double quotes:
string
String Functions
* Get The Length of a String
* The ___ function returns the length of a string.
PHP strlen()
- The example below returns the length of the string “Hello world!”
Example
<html>
<body>
</body>
</html>
OUPUT:
12
Count The Number of Words in a String
The ___ function counts the number of words in a string:
Example
<html>
<body>
</body>
</html>
PHP str_word_count();
OUPUT:
2
Reverse a String
* The ___ function reverses a string:
Example
<html>
<body>
</body>
</html>
PHP strrev(); OUTPUT:
!dlrow olleH
Search For a Specific Text Within a String
* The ___ function searches for a specific text within a string.
* If a match is found, the function ___ of the first match. If no match is found, it will return ___.
* The example below searches for the text “world” in the string “Hello world!”:
Example
<html>
<body>
</body>
</html>
PHP strpos();
returns the character position;
FALSE;
OUPUT:
6
Replace Text Within a String
* The ___ function replaces some characters with some other characters in a string.
* The example below replaces the text “world” with “Dolly”:
Example
<html>
<body>
</body>
</html>
PHP str_replace();
OUPUT:
Hello Dolly!
PHP Integer: An ___ is a non-decimal number between -2,147,483,648 and 2,147,483,647.
integer data type