Programming with php

2,926 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,926
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Programming with php

  1. 1. Creating HTML Forms Pengaturcaraan PHPManaging HTML forms with PHP is a two-step process. First, you createthe HTML form itself, using any text or WYSIWYG editor you choose. Then,you create the corresponding PHP script that will receive and process theform data. An HTML form is created using the form tags and various inputtypes. The form tags look as follows: The most important attribute of your form tag is action, which dictates to which page the form data will be sent. The second attribute — method — has its own issues, but post is the value youll use most frequently. 1
  2. 2. Pengaturcaraan PHPChoosing a MethodThe method attribute of a form dictates how the data is sent to thehandling page. The two options — get and post — refer to the HTTP(Hypertext Transfer Protocol) method to be used. In short, the getmethod sends the submitted data to the receiving page as a series ofname-value pairs appended to the URL.Consider the example shown below:Pengaturcaraan PHPThe benefit of using the get methodis that the resulting page can bebookmarked in the users Webbrowser (since its a URL). For thatmatter, you can also click Back inyour Web browser to return to a getpage, or reload it without problem(neither of which is true for post).Unfortunately, you are limited to howmuch data can be transmitted via getand its less secure (since the data isvisible). 2
  3. 3. Pengaturcaraan PHPPengaturcaraan PHP 3
  4. 4. Pengaturcaraan PHPPengaturcaraan PHP 4
  5. 5. Pengaturcaraan PHPPengaturcaraan PHP 5
  6. 6. Pengaturcaraan PHP Handling an HTML Form 6
  7. 7. Pengaturcaraan PHP Once you have an HTML form, the next step is to write a bare- bones PHP script to handle it. When we say that this script will be handling the form, we mean that it will do something with the data it receives; that is it will reiterate the data back to the Web browser. The PHP page that receives the form data will assign what the user entered into this form element to a special variable called $_REQUEST[weight]. It is very important that the spelling and capitalization match exactly, as PHP is case-sensitive when it comes to variable names. $_REQUEST[weight] can then be used like any other variable: printed, used in mathematical computations, concatenated, and so on. Pengaturcaraan PHPRegistering GlobalsIn earlier versions of PHP, theregister_globals setting was turned on bydefault. This feature gave PHP an ease ofuse by automatically turning form inputsinto similarly named variables, like $nameor $email (as opposed to having to referto $_REQUEST[name] and$_REQUEST[email] first).As of version 4.2 of PHP, thedevelopers behind PHP opted to turn thissetting off by default because not relyingon this feature improves the securityof your scripts. Unfortunately, this also To work around this, there are twohad the side effect that a lot of existing options. First, you could turnscripts no longer worked and manybeginning programmers were stymied register_globals back on, assumingwhen they saw blank values in their that you have administrative controlform results, error messages, or just over your PHP installation. Second,blank pages. you could start using the superglobal variables, such as $_REQUEST, $_GET, and $_POST. 7
  8. 8. Pengaturcaraan PHPPengaturcaraan PHPFollowing the rules outlined before, the data entered into the name forminput, which has a name value of name, will be accessible through thevariable $_REQUEST[name]. The data entered into the email form input,which has a name value of email, will be accessible through$_REQUEST[email]. The same applies to the entered comments data.Again, the spelling and capitalization of your variables here must exactlymatch the corresponding name values in the HTML form. 8
  9. 9. Pengaturcaraan PHPPengaturcaraan PHP 9
  10. 10. Pengaturcaraan PHPPengaturcaraan PHP$_REQUEST$_REQUEST is a special variable type in PHP, available since version4.1. It stores all of the data sent to a PHP page through either the GETor POST methods, as well as data accessible in cookies.Blank pagesIf you see a blank page after submitting the form, first check theHTML source to look for HTML errors, and then confirm thatdisplay_errors is on in your PHP configuration. 10
  11. 11. Pengaturcaraan PHPOthers way to avoid _$_REQUEST[‘variable’]extract($_GET);extract($_POST);extract($_COOKIE);User can call directly the name of variable like $name without usingthe method $_POST[“name”]. Managing Magic Quotes 11
  12. 12. Pengaturcaraan PHPPengaturcaraan PHP 12
  13. 13. Pengaturcaraan PHPIn PHP there are two main types of Magic Quotes: magic_quotes_gpc,which applies to form, URL, and cookie data (gpc stands for get, post,cookie); and magic_quotes_runtime, which applies to data retrievedfrom external files and databases. If Magic Quotes is enabled on yourserver, you can undo its effect using the stripslashes() function. This function will remove any backslashes found in $var.Pengaturcaraan PHP 13
  14. 14. Pengaturcaraan PHP Pengaturcaraan PHPaddslashes() functionYou can emulate what Magic Quotes does if its disabled by using theopposite of the stripslashes() function, addslashes().trim() functionWhen working with strings stemming from forms, its also a good idea touse the trim() function, which removes excess white spaces fromboth ends of the value.$name = trim($name); 14
  15. 15. Conditionals Pengaturcaraan PHPConditionals, like variables, are integral to programming, and most people arefamiliar with them in some form or another. Dynamic Web pages, as you mightimagine, frequently require the use of conditionals to alter a scripts behavioraccording to set criteria.PHPs three primary terms for creating conditionals are if, else, and elseif(which can also be written as two words, else if).Every conditional includes an if clause, as shown here. 15
  16. 16. Pengaturcaraan PHPThe if clause in turn can specify analternate course of action by using else. It can also be written to include another condition and a couple of alternatives by using elseif and else, as in this example. Pengaturcaraan PHPIf a condition is true, the code in thefollowing curly braces ({}) will beexecuted. If not, PHP will continue on.If there is a second condition (after anelseif), that will be checked for truth.The process will continue — you canuse as many elseif clauses as youwant — until PHP hits an else, whichwill be automatically executed at thatpoint, or until the conditionalterminates without an else.For this reason, its important that theelse always come last and be treatedas the default action unless specificcriteria (the conditions) 16
  17. 17. In the second example, a new function, isset(), is introduced. This functionchecks if a variable is set, meaning that it has a value other than NULL.You can also use the comparative and logical operators, listed in the tablebelow, in conjunction with parentheses to make more complicated expressions. SYMBOL MEANING TYPE EXAMPLE $x == $y == is equal to comparison != $x ! = $y is not equal to comparison $x < $y < less than comparison $x > $y > greater than comparison $x <= $y <= less than or equal to comparison $x >= $y >= greater than or equal to comparison ! !$x not logical $x && $y && and logical || or logical $x || $y XOR and not logical $x XOR $y Pengaturcaraan PHP 17
  18. 18. Pengaturcaraan PHPThis is a simple and effective way to validate a form input(particularly a radio button, check box, or select). If the user checks eithergender radio button, then $_REQUEST[gender] will have a value, meaningthat the condition isset($_REQUEST[gender]) is true. In such a case, theshorthand version of this variable — $gender — is assigned the value of$_REQUEST[gender], repeating the technique used with $name, $email,and $comments.If the condition is not true, then $gender is assigned the value of NULL,indicating that it has no value. Notice that NULL is not in quotes. Pengaturcaraan PHP 18
  19. 19. Pengaturcaraan PHPThis if-elseif-else conditional looks at the value of the $gender variable andprints a different message for each possibility. Its very important toremember that the double equals sign (==) means equals, whereas a singleequals sign (=) assigns a value.The distinction is important because the condition $gender == M may ormay not be true, but $gender = M will always be true.Pengaturcaraan PHP 19
  20. 20. Pengaturcaraan PHPSwitchPHP has another type of conditional, called theswitch, best used in place of a long if-elseif-elseconditional. The syntax of switch is shown here.The switch conditional compares the value of$variable to the different cases. When it finds amatch, the following code is executed, up untilthe break. If no match is found, the default isexecuted, assuming it exists (its optional).The switch conditional is limited in its usage in thatit can only check a variables value for equalityagainst certain cases; more complex conditionscannot be easily checked. Pengaturcaraan PHP 20
  21. 21. Validating Form DataPengaturcaraan PHPValidating form data requiresthe use of conditionals andany number of functions,operators, and expressions.One common function to beused is isset(), which tests ifa variable has a value(including 0, FALSE, or anempty string, but not NULL).To check that a user typed something into textual elements like name,email, and comments, you can use the empty() function. It checks if avariable has an empty value — an empty string, 0, NULL, or FALSE. 21
  22. 22. Pengaturcaraan PHPThe first aim of form validation is ensuring that something was entered orselected in form elements. The second goal is to ensure that submitted data isof the right type (numeric, string, etc.), of the right format (like an emailaddress), or a specific acceptable value (like $gender being equal to either Mor F).Next, lets write a new handle_form.php script that makes sure variables havevalues before theyre referenced. Pengaturcaraan PHP 22
  23. 23. Pengaturcaraan PHPPengaturcaraan PHP 23
  24. 24. Pengaturcaraan PHPPengaturcaraan PHP 24
  25. 25. Pengaturcaraan PHPstrlen() functionAnother way of validating text inputs is to use the strlen() function to see ifmore than zero characters were typed.if (strlen($var) > 0) {// $var has a value.} else {// $var does not have a value.} Arrays 25
  26. 26. Pengaturcaraan PHPUnlike strings and numbers (which are scalar variables, meaning they canstore only a single value at a time), an array can hold multiple, separatepieces of information. An array is therefore like a list of values, each valuebeing a string or a number or even another array.Arrays are structured as a series of key-value pairs, where one pair is anitem or element of that array. For each item in the list, there is a key (orindex) associated with it. The resulting structure is not unlike a spreadsheetor database table.PHP supports two kinds of arrays. The first type, called indexed arrays, usesnumbers as the keys, as in the first example, the $artists array. As in mostprogramming languages, with indexed arrays, your arrays will begin with thefirst index at 0, unless you specify the keys explicitly. Key Value 0 Low 1 Aimee Mann 2 Ani DiFranco 3 SpiritualizedThe second type of array, associative, uses strings as keys as in thefollowing example. The $states array uses the state abbreviation for itskeys. Key Value MD Maryland PA Pennsylvania IL Illinois MO Missouri 26
  27. 27. Pengaturcaraan PHPAn array follows the same naming rules as any other variable. So offhand,you might not be able to tell that $var is an array as opposed to a string ornumber. The important syntactical difference has to do with accessingindividual array elements.To retrieve a specific value from an array, you refer to the array name first,followed by the key, in square brackets:Pengaturcaraan PHPBecause arrays use a different syntax than other variables, printing them can betrickier. First, since an array can contain multiple values, you cannot use asimple print statement.Second, the keys in associative arrays complicate printing them and cause aparse error. 27
  28. 28. Pengaturcaraan PHP To work around this, wrap your array name and key in curly braces when your array uses strings for its keys. Numerically indexed arrays dont have this problem.Superglobal ArraysPHP includes several predefined arrays by default. These are the superglobalvariables — $_GET, $_POST, $_SESSION, $_REQUEST, $_SERVER,$_COOKIE, and so forth, added to PHP as of version 4.1.The $_GET variable is where PHP stores all of the variables and values sent to aPHP script via the get method (presumably but not necessarily from an HTMLform). $_POST stores all of the data sent to a PHP script from an HTML formthat uses the post method. Both of these — along with $_COOKIE — aresubsets of $_REQUEST.The superglobals have two benefits over registered global variables. First,they are more secure because they are more precise (they indicate where thevariable came from). Second, they are global in scope (hence the name). If youfind the syntax of these variables to be confusing, you can use the shorthandtechnique at the top of your scripts as follows: 28
  29. 29. Pengaturcaraan PHPPengaturcaraan PHP 29
  30. 30. Pengaturcaraan PHP Pengaturcaraan PHPEarlier versions of PHPThe superglobals are new to PHP as of version 4.1. If you are using anearlier version of the language, use $HTTP_POST_VARS instead of$_POST, and $HTTP_GET_VARS instead of $_GET. 30
  31. 31. Creating and Accessing Arrays Pengaturcaraan PHPCreating ArraysAlthough you can use PHP-generatedarrays, there will frequently be timeswhen you want to create your own.There are two primary ways to defineyour own array. First, you could addone element at a time to build one,as in this example.Its important to understand that ifyou specify a key and a value alreadyexists indexed with that same key, thenew value will overwrite the existingone. In this example, based on thelatest assignment, the value of$array[son] is Michael and that ofarray[2] is orange. 31
  32. 32. Pengaturcaraan PHPInstead of adding one element at a time, you can use the array() function tobuild an entire array in one step.This function can be used whether or not you explicitly set the key.Pengaturcaraan PHPOn the other hand, if you set the first numeric key value, the addedvalues will be keyed incrementally thereafter, as in this example.Finally, if you want to create an array of sequential numbers you can use therange() function. 32
  33. 33. Accessing ArraysIndividual array elements can be accessed by key (e.g., $_POST[email]). Thisworks when you know exactly what the keys are or if you want to refer to only asingle element. To access every array element, use the foreach loop.The foreach loop will iterate through every element in $array, assigning eachelements value to the $value variable. In this example, you can access boththe keys and values. Pengaturcaraan PHP 33
  34. 34. Pengaturcaraan PHPPengaturcaraan PHP 34
  35. 35. Pengaturcaraan PHPPengaturcaraan PHP 35
  36. 36. Pengaturcaraan PHPcount() or sizeof() functionTo determine the number of elements in an array, use the count() orsizeof() function (the two are synonymous):$num=count($array);range() functionThe range() function can also create an array of sequential letters asof PHP 4.1:$alphabet=range(a,z);Error message in foreach loopIf you see an Invalid argument supplied for foreach() errormessage, that means you are trying to use a foreach loop on a variablethat is not an array. Multidimensional Arrays 36
  37. 37. Pengaturcaraan PHPAn arrays values could be any combination of numbers, strings, and evenother arrays. This last option — an array consisting of other arrays — createsa multidimensional array.Multidimensional arrays are much more common than you might expect(especially if you use the superglobals) but remarkably easy to work with. Asan example, lets say you have an array called $states and another one called$provinces for Canada, both created by the following definitions. Pengaturcaraan PHPThese two arrays could be combined into one multidimensional array asfollows: 37
  38. 38. Pengaturcaraan PHP To access the $states array, you refer to $abbr[US] To access Maryland, use $abbr[US][MD] Of course, you can still access multidimensional arrays using the foreach loop, nesting one inside another if necessary.Pengaturcaraan PHPTo print out one of these values, surround the whole construct in curlybraces: 38
  39. 39. Pengaturcaraan PHPPengaturcaraan PHP 39
  40. 40. Pengaturcaraan PHPPengaturcaraan PHP 40
  41. 41. Pengaturcaraan PHPPengaturcaraan PHP 41
  42. 42. Pengaturcaraan PHPPengaturcaraan PHP 42
  43. 43. Pengaturcaraan PHPPengaturcaraan PHP 43
  44. 44. Pengaturcaraan PHPPengaturcaraan PHP 44
  45. 45. Pengaturcaraan PHP$_POST[interests]Even if the user selects only one interest, $_POST[interests] will still bean array because the HTML name for the corresponding input is interests[](the square brackets make it an array).select menuYou can also end up with a multidimensional array by having an HTMLforms select menu allow for multiple selections:‹select name="interests[]" multiple="multiple"› ‹option value="Music"›Music‹/option› ‹option value="Movies"›Movies‹/option› ‹option value="Books"›Books‹/option› ‹option value="Skiing"›Skiing‹/option› ‹option value="Napping"›Napping‹/option›‹/select› Arrays and Strings 45
  46. 46. Pengaturcaraan PHPBecause strings and arrays are so commonly used, PHP has two functionsfor converting between these two variable types.The key to using and understanding these two functions is the separator andglue relationships. When turning an array into a string, you set the glue —the characters or code that will be inserted between the array values in thegenerated string. Conversely, when turning a string into an array, you specifythe separator, which is the code that delineates between the different elementsin the generated array.Lets examine some examples. Pengaturcaraan PHPThe $days_array variable isnow a five-element array,with Mon indexed at 0, Tueindexed at 1, etc.The $string2 variable is nowa comma-separated list ofdays — Mon, Tue, Wed,Thurs, Fri. 46
  47. 47. Pengaturcaraan PHPPengaturcaraan PHP 47
  48. 48. Pengaturcaraan PHPPengaturcaraan PHP 48
  49. 49. Sorting ArraysPengaturcaraan PHPOne of the many advantages arrays have over the other variable types isthe ability to sort them. PHP includes several functions you can use forsorting arrays, all simple in syntax. 49
  50. 50. Pengaturcaraan PHPArray (sort/rsort)Sorting Array :sort($pantry_food); - Sort with ascending 0 - 9rsort($pantry_food); - Sort with Descending 9 – 0Sort with alphabet alphabetasort($pantry_food); - Sort with ascending A - Zarsort($pantry_food); - Sort with Descending Z – APengaturcaraan PHP 50
  51. 51. Pengaturcaraan PHPPengaturcaraan PHP 51
  52. 52. Pengaturcaraan PHPPengaturcaraan PHPArray (Adding/Replace)In array, we can add or change content of arrayexample 1 :$fruit = array(banana,papaya);Cara menambah :<? $fruit[2] = “apple”;print “$fruit[2] ?>The Outputapple 52
  53. 53. Pengaturcaraan PHPArray (merging)You also can merge 2 or more array.Example 1 :$pantry = array( 1 => "apples", 2 => "oranges", 3 => "bananas" );$pantry2 = array( 1 => "potatoes", 2 => "bread", 3 => "tomatoes" );Pengaturcaraan PHPArray (Merging)Way to combine :<?$pantry_food = array_merge ($pantry, $pantry2);?>The Output$pantry_food[0] = "apples";$pantry_food[1] = "oranges";$pantry_food[2] = "bananas";$pantry_food[3] = "potatoes";$pantry_food[4] = "bread";$pantry_food[5] = "tomatoes"; 53
  54. 54. Pengaturcaraan PHPArray (push)The way to add content at the last of array elemt :example$pantry = array(1 => "tomatoes",0 => "oranges",4 => "bananas",3 => "potatoes",2 => "bread");array_push($pantry, "apples"); For and While Loops 54
  55. 55. Two types of loops youll use when managing arrays are for and while.Consider the example of while loop.As long as the condition part of the loop is true, the loop will be executed.Once it becomes false, the loop is stopped. If the condition is never true, theloop will never be executed. The while loop will most frequently be usedwhen retrieving results from a database. Pengaturcaraan PHPThe for loop has a more complicated syntax.Upon first executing the loop, the initial expression is run. Then the conditionis checked and, if true, the contents of the loop are executed. After execution,the closing expression is run and the condition is checked again. Thisprocess continues until the condition is false. Again, the loop will never beexecuted if the condition is never true. 55
  56. 56. Pengaturcaraan PHPConsider this example.The first time this loop is run, the $i variable is set to the value of 1. Thenthe condition is checked (is 1 less than or equal to 10?). Since this istrue, 1 is printed out (echo $i). Then, $i is incremented to 2 ($i++), thecondition is checked, and so forth. The result of this script will be thenumbers 1 through 10 printed out.Pengaturcaraan PHP 56
  57. 57. Pengaturcaraan PHPPengaturcaraan PHP 57
  58. 58. Pengaturcaraan PHP String Manipulation 58
  59. 59. Pengaturcaraan PHPString – “strtok”To take a certain char in the one sentence. The way to take the char canuse “,” “.” or anything elseSntax “strtok(“variable",“condition");”Example :<?php$bigstring = "BigBad Wolf";$firstpart = strtok($bigstring," ");echo "$firstpart";?>The outputBigBadPengaturcaraan PHP String – “substr” To take the char based on position. It start from left and counting start by 0 Syntax “substr(“variable",position,length);” Example : <?php $bigstring = "BigBad Wolf"; $example = substr($bigstring,7,4); echo "$example"; ?> The output Wolf 59
  60. 60. Pengaturcaraan PHPString – “eregi/ereg”To search char in variable. Ereg only can search based on case sensitivesaja.eregi can search without concern about case-sensitiveSyntax “ereg(“condition",“variable");”Syntax “eregi(“condition",“variable");”Pengaturcaraan PHPExample ereg$pattern = "z";$search_area = "My car goes ZOOM.";$search_result = ereg($pattern,$search_area);if ($search_result){// print this if there is a true result.echo "Success, the pattern was found!";} else {// print this if there is a false result.echo "Failure, the pattern was not found!";}OutputFailure, the pattern was not found! 60
  61. 61. Pengaturcaraan PHPExample eregi$pattern = "z";$search_area = "My car goes ZOOM.";$search_result = eregi($pattern,$search_area);if ($search_result){// print this if there is a true result.echo "Success, the pattern was found!";} else {// print this if there is a false result.echo "Failure, the pattern was not found!";}OutputSuccess, the pattern was found!Pengaturcaraan PHPString – “str_replace”Syntax “str_replace(",","", “variable");”To change anything (like coma) to the anything (like $ dollar sign)Contoh :$cfcost1 = “2,300.00”;$cfcost1 = str_replace(",","","$cfcost1");Output :2300.00 61
  62. 62. Pengaturcaraan PHPString – “eregi_replace”To replace char in variable based on searchSyntax: eregi_replace(pattern,replacement,search_area);Example$entry = “user@yahoo.com$pattern = “@";$replacement = “(a)";$entry = ereg_replace($pattern,$replacement,$entry);echo "$entry";outputuser(a)yahoo.comPengaturcaraan PHP String - “strlen” To count total of char in the variable value Syntax “strlen(“variable")” Example : if(strlen($password) < 6) { print “Jumlah password anda kurang dari 6 aksara”; } else { print “Tahniah”; } 62
  63. 63. Pengaturcaraan PHPString - “strstr”To search certain value in variableSyntax “strstr(“variable“,”word to search”)”Example :$member = “pAB7”;if(strstr($member,”AB”)){ print “Membership anda akan luput tidak lama lagi”;}else{ print “Tahniah”;}Pengaturcaraan PHPString - “trim”To clear any blank space in variable at the beginning and endSyntax “trim(“variable“)”Example :$member = “ pAB7 ”;$member = trim($member)print “$member”;Output// print “pAB7”; 63
  64. 64. Pengaturcaraan PHPString - “rtrim”To clear any blank space at the end of variableSyntax “trim(“variable“)”Example :$member = “ pAB7 ”;$member = trim($member)print “$member”;Output// print “ pAB7”;Pengaturcaraan PHPString - “ltrim”To clear any blank space and the begging of variableSyntax “ltrim(“variable“)”Example :$member = “ pAB7 ”;$member = trim($member)print “$member”;Output// print “pAB7 ”; 64
  65. 65. Pengaturcaraan PHPString - “substr_replace”The function same with substr() but it can change the content of variablesyntax “substr_replace(“variable“,”Word To Replace”, position, length)”Contoh :$member = “mz02xyz”;$member = substr_replace($member, “03”, 2, 2)print “$member”;Output// print “mz03xyz”;Pengaturcaraan PHPString - “str_repeat”To repeat the sentence follow by total of number requiredSyntax “str_repeat($string, $n)” : repeat $string $n timesExample :echo str_repeat(*, 10);Output// print “***********”; 65
  66. 66. Pengaturcaraan PHPString - “strtoupper”To convert variable to UPPER CASESyntax “strtoupper(“variable”)”Example :$member = “mzxyz”;$member =strtoupper($member)print “$member”;Output// print “MZXYZ”;Pengaturcaraan PHPString - “strtolower”To convert variable to lowercaseSyntax “strtolower(“variable”)”Example :$member = “MZXYZ”;$member =strtoupper($member)print “$member”;Output// print “mzxyz”; 66
  67. 67. Pengaturcaraan PHPString - “strrchr”To get the value of the end of variable with conditionSyntax “strrchr(“variable”, “aksara”) ”Example :$file = “file.php”;$ext = $ext = substr(strrchr($file, .), 1);print “$ext”;Output// print “php”;Pengaturcaraan PHP String - “wordwrap()” To display variable with the smart appearance which the default can set Syntax “wordwrap(“variable”,”panjang sesuatu ayat”)” Example : $string = “Malaysia negara maju, aman, makmur dan sentoasa”; $string .= “Terdiri daripada 14 buah negeri dan sebuah kerajaan persekutuann”; echo wordwrap($string,75,”<br>”); Output Malaysia negara maju, aman, makmur dan sentoasa Terdiri daripada 14 buah negeri dan sebuah kerajaan persekutuan 67
  68. 68. RandomPengaturcaraan PHPNumber (Random)To get random numberExample :<?php$random_number = rand( );echo "$random_number";?>The output221381276 68
  69. 69. Pengaturcaraan PHPNumber (Random)To get spcific number in random, we must put a value in the ().Example :<?php$random_number = rand(0,10);echo "$random_number";?>The output0Pengaturcaraan PHPPassword Encrypt – md5To encrypt the passwordExample :<?php $passwd = md5($password); echo "$passwd"; ?>The outputddf3rf5765g434dfg676 69
  70. 70. End 70

×