Download presentation
Presentation is loading. Please wait.
1
PHP-language, functions
Jouni Juntunen Oulu University of Applied Sciences School of Business and Information Management
2
Functions Two types of functions
Built-in (in PHP more that 700 prewritten functions available) Custom Gives well-defined structure to software Adds reusability
3
Function syntax Return value Name Parameters
4
Example: mail-function
Send from you application without any spesific knowledge about -protocols or low-level details <? $subject=”The subject”; $message=”Test”; $headers='From:' . $from . "\r\n" . 'X-Mailer: PHP/' . phpversion(); if (mail($to,$subject,$message,$headers)) . . ?>
5
Example: printf-function
Print formatted string Examples: More examples on
6
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)
7
Input validation with functions
Check if input given by user is numerical Validation user following PHP-functions floatval(), intval(), strval() Example Source code
8
Manipulating strings For example: substr, strlen and str_replace
More string functions on
9
Example: Is credit card valid? (Luhn’s formula)
1. 4 * 2 = 8 2. 9 * 1 = 9 3. 2 * 2 = 4 4. 0 * 1 = 0 5. 1 * 2 = 2 6. 9 * 1 = 9 7. 0 * 2 = 0 8. 0 * 1 = 0 9. 7 * 2 (= 14) = 1+ 4 = 5 10. 5 * 1 = 5 11. 2 * 2 = 4 12. 6 * 1 = 6 13. 7 * 2 (=14) = = 5 14. 2 * 1 = 2 15. 7 * 2 (=14) = = 5 6 last number = 64 (64 + 6) %10 ==0
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.