PHP Language (Functions)
PHP Language (Functions)
Jouni Juntunen
Oulu University of Applied Sciences
School of Business and Information Management
Functions
• Two types of functions
– Built-in (in PHP more that 700 prewritten
functions available)
– Custom
<?
$to="[email protected]";
$from=”[email protected]”;
$subject=”The subject”;
$message=”Test”;
$headers='From:' . $from . "\r\n" . 'X-Mailer: PHP/' . phpversion();
if (mail($to,$subject,$message,$headers))
.
.
.
?>
Example: printf-function
• Print formatted string
• Examples:
• More examples on
http://www.w3schools.com/PHP/func_string_
printf.asp
Set HTTP-headers
• Header-function can be used to set HTTP
headers for server’s reply in PHP
• Example: Relocate user (Example and source)
• Example: Promt for username and password
(Example and source on course material and
Ilmari)
Input validation with functions
• Check if input given by user is numerical
• Validation user following PHP-functions
– floatval(), intval(), strval()
• Example
• Source code
Manipulating strings
• For example: substr, strlen and str_replace
• More string functions on
http://us2.php.net/manual/en/ref.strings.php
Example: Is credit card valid? (Luhn’s formula)