IDM 232. Scripting for Interactive Digital Media II. IDM 232: Scripting for IDM II 1

Size: px
Start display at page:

Download "IDM 232. Scripting for Interactive Digital Media II. IDM 232: Scripting for IDM II 1"

Transcription

1 IDM 232 Scripting for Interactive Digital Media II IDM 232: Scripting for IDM II 1

2 PHP HTML-embedded scripting language IDM 232: Scripting for IDM II 2 Before we dive into code, it's important to understand what PHP is. PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.

3 PHP Example - Inline <body> <main> <h1><?php echo 'Hello World';?></h1> </main> </body> IDM 232: Scripting for IDM II 3

4 PHP Example - External <?php function helloworld() { return 'Hello World'; }?> <?php include 'component.php';?> <html> <head>... IDM 232: Scripting for IDM II 4

5 PHP Runs On The Server IDM 232: Scripting for IDM II 5 Let's walk through the difference between client and server side (whiteboard)

6 Server Based Workflow IDM 232: Scripting for IDM II 6 Let's talk about our development workflow. (MAMP demo)

7 Variables IDM 232: Scripting for IDM II 7 Our exploration in the PHP programming language is going to begin with an exploration of the different structures or types that we can use while writing PHP. And the first of those that we're going to look at are variables. You're all familiar with variables from other programming. A variable is a symbolic representation of a value. You can think of it as a symbol that refers to something and that's going to make a lot more sense once we actually start using them. But as it's name suggests, it can change over time or vary. It has a variable value because it can point to different values. Now, in PHP, there's some rules about the kinds of names that we can give to variables.

8 Variable Names Start with $ Followed by letter or underscore Can contain letters, numbers, underscores or dashes No spaces Case-sensitive IDM 232: Scripting for IDM II 8 (click) They need to start with a dollar sign, that needs to be (click) followed by either letter or an underscore, they can (click) contain letters, numbers, underscores or dashes. They (click) cannot contain any spaces and they (click) are case sensitive. It makes a difference whether we use an upper case letter or a lowercase letter.

9 Variable Names - Casing <?php $item $Item?> IDM 232: Scripting for IDM II 9 So let me give you some examples of some variable names and then we can talk about them. So I could have item, which is just $item. I could also have Item with an uppercase I. These are two different variables, with potentially two different values. You want to be consistent with capitalization. Best practice - avoid starting variable names with a capital letter.

10 Variable Names - camelcase <?php $myvariable?> IDM 232: Scripting for IDM II 10 We can also have myvariable with a capital V. That is often referred to as camelcase, because those upper case letters in the middle are like the humps in a camel. So, some developers like that format.

11 Variable Names <?php $this_variable $this-variable?> IDM 232: Scripting for IDM II 11 Then there's the underscore between words, so this_variable. There's also a dash, this-variable.

12 Variable Names <?php $product3 $_book $ bookpage?> IDM 232: Scripting for IDM II 12 You can put numbers in it. So product3, that's perfectly valid to have a third product named that way. You can put underscores in front of it. Remember, the first character has to either be a letter or an underscore, so you could have _book. You could even have multiple underscores, $ bookpage. Now, all of these are valid. Any of these will absolutely work. But I want to steer you towards some and away from others.

13 Best Practices Avoid: hyphenated variable names ($this-variable) multiple underscores ($ bookpage) leading underscore ($_book) IDM 232: Scripting for IDM II 13 The first one is I think we should not use the (click) hyphenated version of this, and the main reason why is that, that hyphen looks like a minus sign, and it looks like we're subtracting this minus variable. And when we start working with variables and we start working with addition and subtraction, that could be confusing for us. So let's avoid confusion and stay away from that. (click) The second one is this multiple underscores. Stay away from that as well, because it makes it hard to tell whether you've got one or two underscores. I once worked on a project where another programmer had written their variable names using underscores. And sometimes they had one underscore, sometimes they had two, sometimes they had three, and it had significance to them. There was a reason why they were using one, two, or three, but it was really kind of lost on me as to what the meaning was behind these, and it was hard to read to tell whether it was one or two or three. (click) The last one is not quite as evil, but I want to steer you away from it and that is this single underscore at the beginning. The reason it's not evil is that PHP is going to use it itself. And we're going to see that. We're going to see that PHP has some special variables. They're named with this underscore at the beginning, and some developers use this underscore for special cases. They want to denote the fact that a variable has certain access privileges, that certain people can or can't access things by putting that underscore in front of it. Because it has this special meaning both to PHP and to other developers. Let's stay away from it for general use.

14 IDM 232: Scripting for IDM II 14 PHP actually has some words that are reserved, words that you're not allowed to use for different things, and it's a good idea to take a review of this list, and then stay away from those words as much as possible. Sometimes, it's not a problem to use it for a variable name, but it might be a problem to use it in other contexts. It's basically just names with special meaning to PHP that we don't want to use.

15 Variables <?php $var1 = 10; echo $var1;?> IDM 232: Scripting for IDM II 15 Let's look at an example. The name of our first variable will be var1 and then we're just going to say it's equal to the number 10. That's it. We've now made that symbolic pointing from the variable to the number 10. Variable 1 now points to 10, and if we talk about variable 1, we're talking about 10. So if we then, in the next line say echo $var1, it's going to echo back 10. It doesn't output var1, it outputs the value of the variable $var1.

16 Variables <?php $var1 = "Hello world"; echo $var1;?> IDM 232: Scripting for IDM II 16 Variables don't only have to point to a number. In this example, the value of $var1 is a string of text Hello world. Variables can point to anything really, they are just a symbolic representation of something larger.

17 Data Type: Strings IDM 232: Scripting for IDM II 17 Strings are a very common feature of most programming languages. And we've already been using Strings without knowing it. A string is a set of characters. Those characters can be letters, numbers, symbols. And their going to be defined inside of quotation marks, either single quotes or double quotes. In non-programming terms, you can think of a string as being text.

18 Strings <?php $var1 = "Hello world"; echo $var1;?> IDM 232: Scripting for IDM II 18 Let's look at our previous example - "Hello world" is an example of a string. The text is defined inside double quotes.

19 Strings <?php $var1 = "<p>hello world</p>"; echo $var1;?> IDM 232: Scripting for IDM II 19 It is perfectly valid to put HTML inside of our string variables. When you output the value of the variable, the HTML tags will be included.

20 Strings <?php $var1 = "Hello world"; $var2 = 'Hello world';?> IDM 232: Scripting for IDM II 20 You can use double or single quotes for your strings, best practice is to use double quotes and we'll see why in a bit.

21 Strings <?php $greeting = "Hello"; $target = "World"; $phrase = $greeting. " ". $target; echo $phrase; // Hello World?> IDM 232: Scripting for IDM II 21 Here's an example - we start with $greeting and assign it's value to be Hello. Then we setup the $target variable and set it's value to World. Next we create a $phrase variable, and set its value equal to our $greeting, and then using the dot to concatenate multiple values, we add another string, which is simply a space, another dot to concatenate the $target value. When we echo the $phrase variable, we get Hello, a space, and then World.

22 Strings $phrase = $greeting. " ". $target; echo "$phrase Again<br>"; // Hello World Again echo '$phrase Again<br>'; // $phrase Again IDM 232: Scripting for IDM II 22 In this example, inside double quotes I tell it to echo the $phrase variable, followed by a space, the word Again and then a break tag. Because of the dollar sign, PHP is going to recognize this as a variable and echo the value of the variable. This however does not work if you use single quotes. This is one of many examples as to why it's better to get in the practice of using double quotes in PHP.

23 String Functions IDM 232: Scripting for IDM II 23 We've seen the basics of working with strings. Now I want us to take a look at some functions that we can use with strings. We haven't looked at a lot of functions yet. So far we've really just looked at the PHP info function and Echo. Those are really the two main functions that we've seen. So we're going to start diving into the world of functions. And before we do, I just want to remind you that the php.net website has some excellent documentation for functions. And it will tell you all of the different functions that are predefined in PHP, it'll tell you how to use them, has good user submitted tips for you, all of that's there. And you can browse through those if you're looking for something, you're not quite sure what it is. Or if you know the name of the function you can just type it into the search bar at the top and it will return the documentation for it directly.

24 String Functions <?php $first = "The quick brown fox"; $second = " jumped over the lazy dog.";?> IDM 232: Scripting for IDM II 24 Here I have two strings (explain). We've seen how to assign variables to strings, and we've seen how to concatenate these together using the dot notation. I'm going to show you another way to concatenate quickly, and actually assign and concatenate at the same time.

25 String Functions <?php $first = "The quick brown fox"; $second = " jumped over the lazy dog."; $third = $first;?> IDM 232: Scripting for IDM II 25 So here we have a third variable, and it's going to be equal to the first.

26 String Functions <?php $first = "The quick brown fox"; $second = " jumped over the lazy dog.";?> $third = $first; $third.= $second; echo $third; IDM 232: Scripting for IDM II 26 Then on a new line, it's going to be $third is equal to concatenated equal to second. So this says third points to the same thing first does. Then on the next line I'm going to tell third that it should add on the second string value to the end, concatenating it to what's already there using the dot equals notation. It's appending to the end, the values of first and second haven't changed. This is going to be very handy later when we have to build up a string over time, especially with MySQL.

27 String Functions Lowercase: <?php echo strtolower($third);?><br> Uppercase: <?php echo strtoupper($third);?><br> Uppercase first: <?php echo ucfirst($third);?><br> Uppercase words: <?php echo ucwords($third);?> IDM 232: Scripting for IDM II 27 Let's take a look at some string functions. This HTML includes some PHP tags calling some functions, the first is stringtolower which is the name of the function. Functions often take something as an argument, which serves as input into the function, and then they return output to you. So the input in this case is going to be inside the parenthesis, and it's going to be our variable $third.

28 String Functions strtolower($third) Lowercase: <?php echo strtolower($third);?><br> Lowercase: the quick brown fox jumped over the lazy dog. IDM 232: Scripting for IDM II 28

29 String Functions strtoupper($third) Uppercase: <?php echo strtoupper($third);?><br> Uppercase: THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. IDM 232: Scripting for IDM II 29

30 String Functions ucfirst($third) Uppercase first: <?php echo ucfirst($third);?><br> Uppercase first: The quick brown fox jumped over the lazy dog. IDM 232: Scripting for IDM II 30

31 String Functions ucwords($third) Uppercase words: <?php echo ucwords($third);?><br> Uppercase words: The Quick Brown Fox Jumped Over The Lazy Dog. IDM 232: Scripting for IDM II 31

32 String Functions strlen Length: <?php echo strlen($third);?> Length: 45 IDM 232: Scripting for IDM II 32 Let's look at a couple more - strlen is going to tell us the length of the string. When we run this we find out the length of this variable is 45 characters; that's the number of characters and spaces in the string.

33 String Functions strstr Find: <?php echo strstr($third, "brown");?><br> Find: brown fox jumped over the lazy dog. IDM 232: Scripting for IDM II 33 Find uses a function named strstr; you're finding a string within a string. So inside $third we're going to look for brown, and see what it returns. The Find did find the word brown. Notice what it returned to us, it returned everything after the find in the string. So it found brown and the result that was returned was not just the word, but everything that follows as well.

34 String Functions str_replace Replace by string: <?php echo str_replace("quick", "super-fast", $third);?> Replace by string: The super-fast brown fox jumped... IDM 232: Scripting for IDM II 34 Replace by string is going to replace quick with super-fast inside $third. Some of these functions take two arguments, others take three. You can use the php.net site to review all the required arguments for any of the predefined functions available in PHP. In this example, we're searching for a needle in a haystack. The haystack is $third and the needle is quick. You can see that it put the super-fast brown fox in place of the word quick.

35 String Functions substr <?php echo substr($third, 5, 10);?> uick brown IDM 232: Scripting for IDM II 35 Substring is going to make a sub string of $third starting at the fifth position to the tenth position of the string.

36 String Functions strpos <?php echo "Find position: ". strpos($third, "brown");?> Find position: 10 IDM 232: Scripting for IDM II 36 String position is going to tell us the position of brown within the string.

37 String Functions IDM 232: Scripting for IDM II 37 So these are your first set of functions. This is the way that PHP is going to work. We're going to be able to manipulate all sorts of things by using different functions, and these are the string functions. These are not the only ones. There are a lot more and I don't expect that you will have memorized all of these. You're going to be looking them up for a while, so they become second nature to you. You're going to have to make yourself some notes. Keep yourself a little chart, maybe jot down the ones, you know, that you use most often. So that there is a handy reference or just keep the PHP.net website open, so that you can quickly go and search and look up, how you use each of these. I've been using PHP a long time and I'm still constantly looking up, the usage of these and the order of the arguments and that kind of thing. Now we've explored strings and string functions. We're ready to move on and look at integers.

38 Numbers: Integers IDM 232: Scripting for IDM II 38 Next we're going to talk about numbers. We'll being by talking about integers (whole numbers). Pretty self explanatory, but we need to know how to work with integers in PHP.

39 Numbers <?php $var1 = 3; $var2 = 4;?> IDM 232: Scripting for IDM II 39

40 Numbers <?php $var1 = 3; $var2 = 4;?> Basic math: <?php echo (( $var1) * $var2) / 2-5?> IDM 232: Scripting for IDM II 40 This is basic math, remember order of operations.

41 Please Excuse My Dear Aunt Sally parentheses exponents multiplication division addition subtraction IDM 232: Scripting for IDM II 41 Order of operations

42 Numbers $var1 = 3; $var2 = 4; Basic math: <?php echo (( $var1) * $var2) / 2-5?> // = 6 * 4 = 24 / 2 = 12-5 = 7 IDM 232: Scripting for IDM II 42

43 Number Functions abs() pow() sqrt() rand() IDM 232: Scripting for IDM II 43 Just like strings, PHP has various functions available for working with numbers. I'm not going to go into detail with each of these, you can look up the information about these and all the available functions on php.net. Some examples include (click) converting a number to an absolute number, (click) raising a number to a specific power, (click) determining the square root of a number and (click) generating a random number.

44 Incrementing $var2 = 4; $var2 = $var2 + 1; IDM 232: Scripting for IDM II 44 Incrementing a number is very common, especially when dealing with loops, which we'll get to next week. If I want to increase the value of $var2 by one, I can use basic math and do that. There is nothing wrong with this code.

45 Incrementing $var2 = 4; // $var2 = $var2 + 1; $var2++; echo $var2; // 5 IDM 232: Scripting for IDM II 45 It is common to use this incrementing technique, which actually comes from the world of C code, with a double plus after the variable name. This will increment the value of $var2 by one.

46 Decrementing $var2 = 4; $var2--; echo $var2; // 3 IDM 232: Scripting for IDM II 46 Same thing with decrementing, just use double minus instead of plus.

47 Numbers: Floating Points IDM 232: Scripting for IDM II 47 Now we've taken a look at integers, I'm going to to take a look at another type of number which are floating point numbers also simply called Floats, for short. You may know them more commonly as decimal numbers. That is numbers that have a decimals in them followed by a number of significant digits 2.75 is an example of a floating point number. Now, it may seem arbitrary to you if you haven't done a lot of programming before that we divide numbers into these two types. Integers and floating point, and the reason why is because computers store integers and floating points in different ways in memory.

48 Numbers: Floating Points <?php echo $float = 3.14;?> IDM 232: Scripting for IDM II 48 This is an example of a floating number.

49 Numbers: Floating Points <?php echo $float = 3.14;?> <?php echo $float + 7;?> <?php echo 4/3;?> IDM 232: Scripting for IDM II 49 Floating numbers can interact with integers, and integers can interact with each other to produce floating numbers.

50 Numbers: Floating Functions <?php echo round($float, 1); // 3.1 echo ceil($float); echo floor($float);?> IDM 232: Scripting for IDM II 50 Here are some examples of PHP functions that work with floats. Again, you can look up the details and all of the available functions on php.net. Rounding will let you define how many decimal points the value should be rounded to. Ceiling and floor are also rounding type functions, ceiling will always round up, floor will always round down.

51 Is Integer/Float? $integer = 3; $float = 3.14; echo "Is {$integer} integer? ". is_int($integer); echo "Is {$float} float? ". is_float($float); IDM 232: Scripting for IDM II 51 We can check variables to see if they are integers or floats using some built in functions.

52 Is Numeric echo "Is {$integer} numeric? ". is_numeric($integer); echo "Is {$float} numeric? ". is_numeric($float); IDM 232: Scripting for IDM II 52 We can also verify if a variable value is numeric in any way. These are all helpful functions to know to verify your variable values as your scripts get more complicated.

53 Arrays IDM 232: Scripting for IDM II 53 Arrays are a common feature in many programming languages. Arrays are going to be extremely useful for helping us to keep information organized. So, what is an array? An array is an ordered, integer-indexed collection of objects. That's a fancy way of saying that we can take objects, like strings and integers and put them into a group and then keep their position in that group in the same order, so that we can refer to those objects by their positions. We can tell the array, give me back the first object, give me the fifth object, and so on, because the objects are going to be indexed according to what position they hold in the array.

54 Arrays <?php $numbers = array(); // PHP 5.4 $numbers = [];?> IDM 232: Scripting for IDM II 54 I'm going to assign the variable $numbers to be an array. You define an array using either of these methods. The second method is available as long as you are running version 5.4 or higher. In this example we've defined an empty array, there are no objects inside the array (yet).

55 Arrays <?php $numbers = [4,8,15,16];?> IDM 232: Scripting for IDM II 55 We can put a series of objects in our array and separate them by commas. So I'm adding some numbers. The numbers are going to stay in the order I've put them in, and I can refer to them by position when I want to get them back out.

56 Arrays <?php $numbers = [4,8,15,16]; echo $numbers[1];?> IDM 232: Scripting for IDM II 56 To retrieve something from the array, we're going to use the echo command, and we're going to reference the variable $numbers because that's what points to our array, and then we're going to use square brackets. Inside those square brackets, we're going to provide the index that we want it to return. In this case it will return whatever is in position 1. What should I expect to see?

57 Arrays <?php $numbers = [4,8,15,16]; echo $numbers[1]; // 8?> IDM 232: Scripting for IDM II 57 The object returned is 8, which we would normally expect to be in the second pocket of our array. This brings up a very important point about arrays.

58 Arrays <?php $numbers = [`0`,`1`,`2`];?> IDM 232: Scripting for IDM II 58 Arrays are numbered starting from zero. The first pocket is indexed as zero, second is indexed as 1 and so on. This is how all arrays work, not only in PHP, but in every programming language. It will take some getting used to.

59 Arrays <?php $numbers = [4,8,15,16]; echo $numbers[0]; // 4?> IDM 232: Scripting for IDM II 59 So if we want to extract the item in "pocket 1" we use an index value of zero.

60 Arrays <?php $mixed = [6, "fox", "dog", ["x", "y", "z"]];?> IDM 232: Scripting for IDM II 60 And as I said, an array can contain lots of different types of objects. So, for example, we can have a mixed type object. We'll call it mixed, and inside there, we'll have an array. And in that array, let's put the number 6, the word fox, followed by the word dog, followed by another array. Then in that array we'll put x and y and z. So you see how that works? It doesn't matter what kind of objects we put in there. It can be integers, it can be strings, it can even be other arrays. Any valid type in PHP can go inside an array.

61 Arrays <?php $mixed = [6, "fox", "dog", ["x", "y", "z"]]; echo $mixed[2];?> IDM 232: Scripting for IDM II 61 Let's echo back one of those values. Let's ask for what's in pocket number two. What should be returned?

62 Arrays <?php $mixed = [6, "fox", "dog", ["x", "y", "z"]]; echo $mixed[2]; // dog?> IDM 232: Scripting for IDM II 62

63 Arrays <?php $mixed = [6, "fox", "dog", ["x", "y", "z"]]; echo $mixed[3];?> IDM 232: Scripting for IDM II 63 What are we going to get back if we ask for pocket three?

64 Arrays <?php $mixed = [6, "fox", "dog", ["x", "y", "z"]]; echo $mixed[3]; // Array?> IDM 232: Scripting for IDM II 64 PHP will return to us Array. It's telling us that the object we are requesting is itself an array.

65 Arrays <?php $mixed = [6, "fox", "dog", ["x", "y", "z"]]; echo $mixed[3][1];?> IDM 232: Scripting for IDM II 65 If we want to get a value from this internal array, we'll access pocket three again, and then use a second set of brackets to specify which pocket within the second array we want to access.

66 Arrays <?php $mixed = [6, "fox", "dog", ["x", "y", "z"]]; echo $mixed[3][1]; // y?> IDM 232: Scripting for IDM II 66 So in this case we're going into array 1 ($mixed)[pocket 3] -> array 2[pocket 1] which is "y".

67 Arrays - Assigning Values IDM 232: Scripting for IDM II 67 Now we're able to pull things out of the array, but we also want to assign values into the array. We don't want to have to redefine the entire array each time.

68 Arrays - Assigning Values $mixed[2] = "cat"; $mixed[4] = "mouse"; IDM 232: Scripting for IDM II 68 We can use an assignment operator to add "cat" to pocket number two of our array. We add "mouse" to pocket four the same way. But wait...

69 Arrays - Assigning Values $mixed = [6, "fox", "dog", ["x", "y", "z"]]; $mixed[4] = "mouse"; IDM 232: Scripting for IDM II 69 Our array doesn't have a fourth pocket. That's okay - it's going to put the item in the fourth position for us. What if we don't know the next available open pocket?

70 Arrays - Assigning Values $mixed[] = "horse"; IDM 232: Scripting for IDM II 70 If you don't know how long an array is and you want to add something to the end, you can leave the assignment value blank. So in this example, "horse" will be added to the fifth position, which is the next available position in the array.

71 Arrays = Power $ _001 = "ps42@drexel.edu"; $ _002 = "jht23@drexel.edu"; $ _003 = "jwt26@drexel.edu"; // $ _addresses = [ "ps42@drexel.edu","jht23@drexel.edu","jwt26@drexel.edu" ]; IDM 232: Scripting for IDM II 71 So the power of arrays, is that a set of information can be referenced by a single variable. Imagine if we have one thousand addresses. We wouldn't want to create one thousand variables for those, instead we can assign all of them to an array, and then use one easy to reference variable to pull up each address by its index. The other thing that's powerful about arrays is that they keep their information in the same order unless we change it. Whatever we put in the first pocket stays in the first pocket. So, arrays are good for keeping ordered lists. We can sort those addresses and then they'll be kept in that order for us by the array. You can imagine how arrays are going to start helping us when we start pulling records and data out of our database. We can retrieve 50 customer records sorted alphabetically by last name and store them in the array. And they'll stay sorted in that array by last name.

72 Associative Arrays IDM 232: Scripting for IDM II 72 PHP has another type of array, called an associative array. And it's important for us to learn how to use both types, and to understand the difference between them. An associative array is an object-indexed collection of objects and it's very similar to what we saw for the definition of a regular array. But notice that it doesn't say that it's ordered anymore. And instead of being integer-indexed it is object-indexed, that is, they're going to be indexed by a label of some sort.

73 Array Comparison Basic arrays: When order is most important Associative When having a reference label is most important IDM 232: Scripting for IDM II 73 If we have 100 customers and we store all of their information in an array, is it more important to order the customers in a specific way, or would we want to be able to ask for the customer's last name, or address, without having to remember which pocket within the array holds that information?

74 Associative Arrays <?php $assoc = [];?> IDM 232: Scripting for IDM II 74 So here's an empty array. Until we put something inside the array it doesn't really matter if it's a regular or associative array.

75 Associative Arrays <?php $assoc = ["first_name" => "Dolores"];?> IDM 232: Scripting for IDM II 75 Here I put first name as a label, that's a string, an object, it's object-indexed. And I point that using an equal sign and the greater than sign, so it looks like an arrow pointing to the next data, which is the value. So the key is first name and the value is Dolores. And we can have more than one, key/value pairing.

76 Associative Arrays <?php $assoc = [ "first_name" => "Dolores", "last_name" => "Abernathy" ];?> IDM 232: Scripting for IDM II 76 That is what an associated array looks like. Instead of being indexed by position, it's going to be indexed by the key.

77 Associative Arrays <?php $assoc = [ "first_name" => "Dolores", "last_name" => "Abernathy" ]; echo $assoc["first_name"]; // Dolores?> IDM 232: Scripting for IDM II 77 So if I wanted to get back the first name, I can echo the variable assoc, then in square brackets, the value will be the key instead of the position, in this case first_name.

78 Array Functions IDM 232: Scripting for IDM II 78 There are a lot of functions for working with arrays, and we are going to use them in a lot of different contexts. We'll look at a couple of the common functions, remember you can review all of the available functions and how to use them on php.net.

79 Array Functions <?php $numbers = [8,23,15,42,16,4];?> IDM 232: Scripting for IDM II 79 We'll start with an array filled with numbers. One of the things we're going to look at is how we can sort those numbers. Before we do that, let's look at a couple other functions.

80 Array Functions <?php $numbers = [8,23,15,42,16,4];?> Count: <?php echo count($numbers);?> // 6 Max value: <?php echo max($numbers);?> // 42 Min value: <?php echo min($numbers);?> // 4 IDM 232: Scripting for IDM II 80 The count function will tell us how many items are in the array. max will tell us the maximum value, min the minimum value.

81 Array Functions <?php $numbers = [8,23,15,42,16,4];?> Sort: <?php sort($numbers); print_r($numbers);?> Reverse sort: <?php rsort($numbers); print_r($numbers);?> IDM 232: Scripting for IDM II 81 We can also sort those values, using sort and rsort. I'm also using a new function here print_r which is a debugging tool that will allow us to see the values of an array in the browser (example).

82 Array Functions <?php $numbers = [8,23,15,42,16,4];?> Sort: <?php sort($numbers); print_r($numbers);?> Implode: <?php echo $num_string = implode(" * ", $numbers);?> // 42 * 23 * 16 * 15 * 8 * 4 IDM 232: Scripting for IDM II 82 Another handy function is how we can turn an array into a string. We can combine values together to get a string using implode. The first argument is what the separator is between each of those elements. So here, I've said that it's a space, asterisk and a space. The $num_string variable isn't an array anymore, it's a string.

83 Array Functions <?php $numbers = [8,23,15,42,16,4];?> Sort: <?php sort($numbers); print_r($numbers);?> Implode: <?php echo $num_string = implode(" * ", $numbers);?> Explode: <?php print_r(explode(" * ", $num_string));?> IDM 232: Scripting for IDM II 83 The opposite of implode is explode, which is going to take a string like $num_string and every time it finds this first parameter string (" * "), it's going to use it as a divider between values. So every time is sees a space and then an asterisk space, it's going to split the string into a new object in the array.

84 Array Functions <?php $numbers = [8,23,15,42,16,4];?> 15 in array? <?php echo in_array(15, $numbers); // returns T/F 19 in array? <?php echo in_array(19, $numbers); // returns T/F 15 in array? 1 19 in array? IDM 232: Scripting for IDM II 84 in_array allows us to find out if a value is in an array. It returns a true or false, if true, the function returns a 1, if false then nothing is returned.

85 php.net/manual/en/ref.array.php IDM 232: Scripting for IDM II 85

86 Booleans IDM 232: Scripting for IDM II 86 A Boolean is a programming type that can either be true or false. That's it, one of those two values. And true is not the string true or even the number one. It's just simply the value true. Booleans are very useful in programming because we can use them when performing tests. For example, we used the in_array function to test whether an integer was inside of an array. The result was that the test was a Boolean, true if the integer was present, false if it was not. Let's start by creating ourselves a new workspace for this.

87 Booleans $result1 = true; $result2 = false; echo $result1; // 1 echo $result2; // IDM 232: Scripting for IDM II 87 A boolean is simply the value true or false; notice there are no quotes around that. It's not a string. We are assigning a boolean to a variable, just like we do anything else. and we can echo those values back just like any other variables. A value of true will return a 1, a value of false will output nothing, not a zero.

88 Booleans $result1 = true; $result2 = false; result2 is boolean? <?php echo is_bool($result2);?> // result2 is boolean? 1 IDM 232: Scripting for IDM II 88 The is_bool function will help us find out if something is a boolean. In this case, it's going to return true, represented as a 1 since $result2 is a boolean.

89 Booleans if (something is TRUE) do this otherwise do that IDM 232: Scripting for IDM II 89 Being able to check if something is true or false is going to be incredibly helpful when we get into writing conditional statements, i.e. if something is true do this, otherwise do that.

90 Constants IDM 232: Scripting for IDM II 90 Everything we've covered today has focused on variables. It's fitting that we end with constants, which is the opposite of a variable. A variable can change or vary, a constant can't change. It remains constantly set at the same value. Constants are going to be recognizable on PHP because they're always written in all capital letters and there's no dollar sign in front of them. They're also going to differ from variables in another way. The only way to set a value for constant is to use a function. The define function. You can't just use the equal sign to assign a value, like you can with variable.

91 Constants <?php $max_width = 980;?> IDM 232: Scripting for IDM II 91 Let's say we had a max width equals 980. That would be a variable set at the integer 980.

92 Constants <?php $max_width = 980; MAX_WIDTH = 980; //!! Does not work?> IDM 232: Scripting for IDM II 92 But if it was a constant, max width would not have a dollar sign in front of it and would be in all capital letters. This doesn't work with constants.

93 Constants <?php $max_width = 980; define("max_width", 980); echo MAX_WIDTH;?> IDM 232: Scripting for IDM II 93 We have to use a special function to define a constant, the define function. Then we're going to provide the name of the constant, in quotes, and then the second argument will be the value we want to set it to. We have to use quotes when defining the constant so we can tell PHP the string we want to use for the name of the constant.

94 Constants <?php $max_width = 980; define("max_width", 980); MAX_WIDTH = MAX_WIDTH + 1; // Doesn't work MAX_WIDTH++; // Doesn't work?> IDM 232: Scripting for IDM II 94 With constants, you can not change the value. Once PHP has executed your scripts, the values are locked down.

95 For Next Week... IDM 232: Scripting for IDM II 95

BEGINNER PHP Table of Contents

BEGINNER PHP Table of Contents Table of Contents 4 5 6 7 8 9 0 Introduction Getting Setup Your first PHP webpage Working with text Talking to the user Comparison & If statements If & Else Cleaning up the game Remembering values Finishing

More information

Chapter 1 Operations With Numbers

Chapter 1 Operations With Numbers Chapter 1 Operations With Numbers Part I Negative Numbers You may already know what negative numbers are, but even if you don t, then you have probably seen them several times over the past few days. If

More information

MITOCW watch?v=0jljzrnhwoi

MITOCW watch?v=0jljzrnhwoi MITOCW watch?v=0jljzrnhwoi The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

MITOCW watch?v=rvrkt-jxvko

MITOCW watch?v=rvrkt-jxvko MITOCW watch?v=rvrkt-jxvko The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

MITOCW watch?v=se4p7ivcune

MITOCW watch?v=se4p7ivcune MITOCW watch?v=se4p7ivcune The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

MITOCW watch?v=kz7jjltq9r4

MITOCW watch?v=kz7jjltq9r4 MITOCW watch?v=kz7jjltq9r4 PROFESSOR: We're going to look at the most fundamental of all mathematical data types, namely sets, and let's begin with the definitions. So informally, a set is a collection

More information

URLs and web servers. Server side basics. URLs and web servers (cont.) URLs and web servers (cont.) Usually when you type a URL in your browser:

URLs and web servers. Server side basics. URLs and web servers (cont.) URLs and web servers (cont.) Usually when you type a URL in your browser: URLs and web servers 2 1 Server side basics http://server/path/file Usually when you type a URL in your browser: Your computer looks up the server's IP address using DNS Your browser connects to that IP

More information

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods COMP-202 Unit 2: Java Basics CONTENTS: Using Expressions and Variables Types Strings Methods Assignment 1 Assignment 1 posted on WebCt and course website. It is due May 18th st at 23:30 Worth 6% Part programming,

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

If Statements, For Loops, Functions

If Statements, For Loops, Functions Fundamentals of Programming If Statements, For Loops, Functions Table of Contents Hello World Types of Variables Integers and Floats String Boolean Relational Operators Lists Conditionals If and Else Statements

More information

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */ Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

PHP. Interactive Web Systems

PHP. Interactive Web Systems PHP Interactive Web Systems PHP PHP is an open-source server side scripting language. PHP stands for PHP: Hypertext Preprocessor One of the most popular server side languages Second most popular on GitHub

More information

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between MITOCW Lecture 10A [MUSIC PLAYING] PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between all these high-level languages like Lisp and the query

More information

The following content is provided under a Creative Commons license. Your support

The following content is provided under a Creative Commons license. Your support MITOCW Recitation 2 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality educational resources for free. To make

More information

MITOCW watch?v=flgjisf3l78

MITOCW watch?v=flgjisf3l78 MITOCW watch?v=flgjisf3l78 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality educational resources for free. To

More information

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology.

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology. Guide to and Hi everybody! In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology. This guide focuses on two of those symbols: and. These symbols represent concepts

More information

MITOCW watch?v=4dj1oguwtem

MITOCW watch?v=4dj1oguwtem MITOCW watch?v=4dj1oguwtem PROFESSOR: So it's time to examine uncountable sets. And that's what we're going to do in this segment. So Cantor's question was, are all sets the same size? And he gives a definitive

More information

What is PHP? [1] Figure 1 [1]

What is PHP? [1] Figure 1 [1] PHP What is PHP? [1] PHP is an acronym for "PHP: Hypertext Preprocessor" PHP is a widely-used, open source scripting language PHP scripts are executed on the server PHP is free to download and use Figure

More information

Let's Look Back. We talked about how to create a form in HTML. Forms are one way to interact with users

Let's Look Back. We talked about how to create a form in HTML. Forms are one way to interact with users Introduction to PHP Let's Look Back We talked about how to create a form in HTML Forms are one way to interact with users Users can enter information into forms which can be used by you (programmer) We

More information

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG 1 Notice Assignments Reading Assignment: Chapter 3: Introduction to Parameters and Objects The Class 10 Exercise

More information

Instructor s Notes Web Data Management PHP Sequential Processing Syntax. Web Data Management PHP Sequential Processing Syntax

Instructor s Notes Web Data Management PHP Sequential Processing Syntax. Web Data Management PHP Sequential Processing Syntax Instructor s Web Data Management PHP Sequential Processing Syntax Web Data Management 152-155 PHP Sequential Processing Syntax Quick Links & Text References PHP tags in HTML Pages Comments Pages 48 49

More information

Ex: If you use a program to record sales, you will want to remember data:

Ex: If you use a program to record sales, you will want to remember data: Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:

More information

COMS 469: Interactive Media II

COMS 469: Interactive Media II COMS 469: Interactive Media II Agenda Review Conditional Statements String and Numeric Functions Arrays Review PHP History Rasmus Lerdorf 1995 Andi Gutmans & Zeev Suraski Versions 1998 PHP 2.0 2000 PHP

More information

Lesson 3: Basic Programming Concepts

Lesson 3: Basic Programming Concepts 3 ICT Gaming Essentials Lesson 3: Basic Programming Concepts LESSON SKILLS After completing this lesson, you will be able to: Explain the types and uses of variables and operators in game programming.

More information

An Introduction to Maple This lab is adapted from a lab created by Bob Milnikel.

An Introduction to Maple This lab is adapted from a lab created by Bob Milnikel. Some quick tips for getting started with Maple: An Introduction to Maple This lab is adapted from a lab created by Bob Milnikel. [Even before we start, take note of the distinction between Tet mode and

More information

CCBC Math 081 Order of Operations Section 1.7. Step 2: Exponents and Roots Simplify any numbers being raised to a power and any numbers under the

CCBC Math 081 Order of Operations Section 1.7. Step 2: Exponents and Roots Simplify any numbers being raised to a power and any numbers under the CCBC Math 081 Order of Operations 1.7 1.7 Order of Operations Now you know how to perform all the operations addition, subtraction, multiplication, division, exponents, and roots. But what if we have a

More information

PROFESSOR: Well, yesterday we learned a bit about symbolic manipulation, and we wrote a rather stylized

PROFESSOR: Well, yesterday we learned a bit about symbolic manipulation, and we wrote a rather stylized MITOCW Lecture 4A PROFESSOR: Well, yesterday we learned a bit about symbolic manipulation, and we wrote a rather stylized program to implement a pile of calculus rule from the calculus book. Here on the

More information

Python Intro GIS Week 1. Jake K. Carr

Python Intro GIS Week 1. Jake K. Carr GIS 5222 Week 1 Why Python It s simple and easy to learn It s free - open source! It s cross platform IT S expandable!! Why Python: Example Consider having to convert 1,000 shapefiles into feature classes

More information

Microsoft Office Excel Use Excel s functions. Tutorial 2 Working With Formulas and Functions

Microsoft Office Excel Use Excel s functions. Tutorial 2 Working With Formulas and Functions Microsoft Office Excel 2003 Tutorial 2 Working With Formulas and Functions 1 Use Excel s functions You can easily calculate the sum of a large number of cells by using a function. A function is a predefined,

More information

Chapter 17. Fundamental Concepts Expressed in JavaScript

Chapter 17. Fundamental Concepts Expressed in JavaScript Chapter 17 Fundamental Concepts Expressed in JavaScript Learning Objectives Tell the difference between name, value, and variable List three basic data types and the rules for specifying them in a program

More information

Blitz2D Newbies: Definitive Guide to Types by MutteringGoblin

Blitz2D Newbies: Definitive Guide to Types by MutteringGoblin Blitz2D Newbies: Definitive Guide to Types by MutteringGoblin Types are probably the hardest thing to understand about Blitz Basic. If you're using types for the first time, you've probably got an uneasy

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

DOWNLOAD PDF MICROSOFT EXCEL ALL FORMULAS LIST WITH EXAMPLES

DOWNLOAD PDF MICROSOFT EXCEL ALL FORMULAS LIST WITH EXAMPLES Chapter 1 : Examples of commonly used formulas - Office Support A collection of useful Excel formulas for sums and counts, dates and times, text manipularion, conditional formatting, percentages, Excel

More information

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid: 1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,

More information

Linked Lists. What is a Linked List?

Linked Lists. What is a Linked List? Linked Lists Along with arrays, linked lists form the basis for pretty much every other data stucture out there. This makes learning and understand linked lists very important. They are also usually the

More information

The following content is provided under a Creative Commons license. Your support

The following content is provided under a Creative Commons license. Your support MITOCW Recitation 4 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To make

More information

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh C++ PROGRAMMING For Industrial And Electrical Engineering Instructor: Ruba A. Salamh CHAPTER TWO: Fundamental Data Types Chapter Goals In this chapter, you will learn how to work with numbers and text,

More information

Week - 01 Lecture - 04 Downloading and installing Python

Week - 01 Lecture - 04 Downloading and installing Python Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 04 Downloading and

More information

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5 Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5 [talking head] Formal Methods of Software Engineering means the use of mathematics as an aid to writing programs. Before we can

More information

Skill 1: Multiplying Polynomials

Skill 1: Multiplying Polynomials CS103 Spring 2018 Mathematical Prerequisites Although CS103 is primarily a math class, this course does not require any higher math as a prerequisite. The most advanced level of mathematics you'll need

More information

What did we talk about last time? Examples switch statements

What did we talk about last time? Examples switch statements Week 4 - Friday What did we talk about last time? Examples switch statements History of computers Hardware Software development Basic Java syntax Output with System.out.print() Mechanical Calculation

More information

Intro. Classes & Inheritance

Intro. Classes & Inheritance Intro Functions are useful, but they're not always intuitive. Today we're going to learn about a different way of programming, where instead of functions we will deal primarily with objects. This school

More information

MITOCW MIT6_01SC_rec2_300k.mp4

MITOCW MIT6_01SC_rec2_300k.mp4 MITOCW MIT6_01SC_rec2_300k.mp4 KENDRA PUGH: Hi. I'd like to talk to you today about inheritance as a fundamental concept in object oriented programming, its use in Python, and also tips and tricks for

More information

The following content is provided under a Creative Commons license. Your support

The following content is provided under a Creative Commons license. Your support MITOCW Recitation 1 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality educational resources for free. To make

More information

PROFESSOR: So far in this course we've been talking a lot about data abstraction. And remember the idea is that

PROFESSOR: So far in this course we've been talking a lot about data abstraction. And remember the idea is that MITOCW Lecture 4B [MUSIC-- "JESU, JOY OF MAN'S DESIRING" BY JOHANN SEBASTIAN BACH] PROFESSOR: So far in this course we've been talking a lot about data abstraction. And remember the idea is that we build

More information

Square Roots: Introduction & Simplification

Square Roots: Introduction & Simplification Square Roots: Introduction & Simplification You already know about squaring. For instance, 2 2 = 4, 3 2 = 9, etc. The backwards of squaring is square-rooting. The symbol for square-rooting is " ", the

More information

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Table of Contents Introduction!... 1 Part 1: Entering Data!... 2 1.a: Typing!... 2 1.b: Editing

More information

Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel

Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel Introduction: PHP (Hypertext Preprocessor) was invented by Rasmus Lerdorf in 1994. First it was known as Personal Home Page. Later

More information

Binary, Hexadecimal and Octal number system

Binary, Hexadecimal and Octal number system Binary, Hexadecimal and Octal number system Binary, hexadecimal, and octal refer to different number systems. The one that we typically use is called decimal. These number systems refer to the number of

More information

Activity 1 Creating a simple gradebook

Activity 1 Creating a simple gradebook Activity 1 Creating a simple gradebook 1 Launch Excel to start a new spreadsheet a. Click on the Excel icon to start a new workbook, either from the start menu, Office Toolbar, or an Excel icon on the

More information

6.001 Notes: Section 8.1

6.001 Notes: Section 8.1 6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything

More information

Sequence of Characters. Non-printing Characters. And Then There Is """ """ Subset of UTF-8. String Representation 6/5/2018.

Sequence of Characters. Non-printing Characters. And Then There Is   Subset of UTF-8. String Representation 6/5/2018. Chapter 4 Working with Strings Sequence of Characters we've talked about strings being a sequence of characters. a string is indicated between ' ' or " " the exact sequence of characters is maintained

More information

My Favorite bash Tips and Tricks

My Favorite bash Tips and Tricks 1 of 6 6/18/2006 7:44 PM My Favorite bash Tips and Tricks Prentice Bisbal Abstract Save a lot of typing with these handy bash features you won't find in an old-fashioned UNIX shell. bash, or the Bourne

More information

The following content is provided under a Creative Commons license. Your support

The following content is provided under a Creative Commons license. Your support MITOCW Lecture 10 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality educational resources for free. To make a

More information

Introduction to Python Code Quality

Introduction to Python Code Quality Introduction to Python Code Quality Clarity and readability are important (easter egg: type import this at the Python prompt), as well as extensibility, meaning code that can be easily enhanced and extended.

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to:

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to: Get JAVA To compile programs you need the JDK (Java Development Kit). To RUN programs you need the JRE (Java Runtime Environment). This download will get BOTH of them, so that you will be able to both

More information

Chapter 2 Working with Data Types and Operators

Chapter 2 Working with Data Types and Operators JavaScript, Fourth Edition 2-1 Chapter 2 Working with Data Types and Operators At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics

More information

There are functions to handle strings, so we will see the notion of functions itself in little a detail later. (Refer Slide Time: 00:12)

There are functions to handle strings, so we will see the notion of functions itself in little a detail later. (Refer Slide Time: 00:12) Programming Data Structures, Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Module - 13b Lecture - 19 Functions to handle strings;

More information

PHP 5 Introduction. What You Should Already Know. What is PHP? What is a PHP File? What Can PHP Do? Why PHP?

PHP 5 Introduction. What You Should Already Know. What is PHP? What is a PHP File? What Can PHP Do? Why PHP? PHP 5 Introduction What You Should Already Know you should have a basic understanding of the following: HTML CSS What is PHP? PHP is an acronym for "PHP: Hypertext Preprocessor" PHP is a widely-used, open

More information

Working with Strings. Husni. "The Practice of Computing Using Python", Punch & Enbody, Copyright 2013 Pearson Education, Inc.

Working with Strings. Husni. The Practice of Computing Using Python, Punch & Enbody, Copyright 2013 Pearson Education, Inc. Working with Strings Husni "The Practice of Computing Using Python", Punch & Enbody, Copyright 2013 Pearson Education, Inc. Sequence of characters We've talked about strings being a sequence of characters.

More information

COMS 469: Interactive Media II

COMS 469: Interactive Media II COMS 469: Interactive Media II Agenda Review Ch. 5: JavaScript An Object-Based Language Ch. 6: Programming the Browser Review Data Types & Variables Data Types Numeric String Boolean Variables Declaring

More information

Client Side JavaScript and AJAX

Client Side JavaScript and AJAX Client Side JavaScript and AJAX Client side javascript is JavaScript that runs in the browsers of people using your site. So far all the JavaScript code we've written runs on our node.js server. This is

More information

CHAPTER 1: INTEGERS. Image from CHAPTER 1 CONTENTS

CHAPTER 1: INTEGERS. Image from  CHAPTER 1 CONTENTS CHAPTER 1: INTEGERS Image from www.misterteacher.com CHAPTER 1 CONTENTS 1.1 Introduction to Integers 1. Absolute Value 1. Addition of Integers 1.4 Subtraction of Integers 1.5 Multiplication and Division

More information

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment

More information

Course contents. Overview: Goodbye, calculator. Lesson 1: Get started. Lesson 2: Use cell references. Lesson 3: Simplify formulas by using functions

Course contents. Overview: Goodbye, calculator. Lesson 1: Get started. Lesson 2: Use cell references. Lesson 3: Simplify formulas by using functions Course contents Overview: Goodbye, calculator Lesson 1: Get started Lesson 2: Use cell references Lesson 3: Simplify formulas by using functions Overview: Goodbye, calculator Excel is great for working

More information

Microsoft Office Excel 2010 Extra

Microsoft Office Excel 2010 Extra Microsoft Office Excel 2010 Extra Excel Formulas İçindekiler Microsoft Office... 1 A.Introduction... 3 1.About This Tutorial... 3 About this tutorial... 3 B.Formula and Function Basics... 4 2.Simple Formulas...

More information

9. Elementary Algebraic and Transcendental Scalar Functions

9. Elementary Algebraic and Transcendental Scalar Functions Scalar Functions Summary. Introduction 2. Constants 2a. Numeric Constants 2b. Character Constants 2c. Symbol Constants 2d. Nested Constants 3. Scalar Functions 4. Arithmetic Scalar Functions 5. Operators

More information

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet. Mr G s Java Jive #2: Yo! Our First Program With this handout you ll write your first program, which we ll call Yo. Programs, Classes, and Objects, Oh My! People regularly refer to Java as a language that

More information

SEER AKADEMI LINUX PROGRAMMING AND SCRIPTINGPERL 7

SEER AKADEMI LINUX PROGRAMMING AND SCRIPTINGPERL 7 SEER AKADEMI LINUX PROGRAMMING AND SCRIPTINGPERL 7 Hi everyone once again welcome to this lecture we are actually the course is Linux programming and scripting we have been talking about the Perl, Perl

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

Regular Expressions Explained

Regular Expressions Explained Found at: http://publish.ez.no/article/articleprint/11/ Regular Expressions Explained Author: Jan Borsodi Publishing date: 30.10.2000 18:02 This article will give you an introduction to the world of regular

More information

GENERAL MATH FOR PASSING

GENERAL MATH FOR PASSING GENERAL MATH FOR PASSING Your math and problem solving skills will be a key element in achieving a passing score on your exam. It will be necessary to brush up on your math and problem solving skills.

More information

Programming Fundamentals and Python

Programming Fundamentals and Python Chapter 2 Programming Fundamentals and Python This chapter provides a non-technical overview of Python and will cover the basic programming knowledge needed for the rest of the chapters in Part 1. It contains

More information

Welcome to 5 th Grade Math Review Properties of Operations

Welcome to 5 th Grade Math Review Properties of Operations Welcome to 5 th Grade Math Review Properties of Operations What do you notice in this chart? Are there any patterns? Powers of Ten Strategy Time Interactive Math Journal Today s Lesson: Review of Properties

More information

6.001 Notes: Section 15.1

6.001 Notes: Section 15.1 6.001 Notes: Section 15.1 Slide 15.1.1 Our goal over the next few lectures is to build an interpreter, which in a very basic sense is the ultimate in programming, since doing so will allow us to define

More information

Introduction to TURING

Introduction to TURING Introduction to TURING Comments Some code is difficult to understand, even if you understand the language it is written in. To that end, the designers of programming languages have allowed us to comment

More information

How to Improve Your Campaign Conversion Rates

How to Improve Your  Campaign Conversion Rates How to Improve Your Email Campaign Conversion Rates Chris Williams Author of 7 Figure Business Models How to Exponentially Increase Conversion Rates I'm going to teach you my system for optimizing an email

More information

Access Intermediate

Access Intermediate Access 2013 - Intermediate 103-134 Advanced Queries Quick Links Overview Pages AC124 AC125 Selecting Fields Pages AC125 AC128 AC129 AC131 AC238 Sorting Results Pages AC131 AC136 Specifying Criteria Pages

More information

A lot of people make repeated mistakes of not calling their functions and getting errors. Make sure you're calling your functions.

A lot of people make repeated mistakes of not calling their functions and getting errors. Make sure you're calling your functions. Handout 2 Functions, Lists, For Loops and Tuples [ ] Functions -- parameters/arguments, "calling" functions, return values, etc. Please make sure you understand this example: def square(x): return x *

More information

Choose the file menu, and select Open. Input to be typed at the Maple prompt. Output from Maple. An important tip.

Choose the file menu, and select Open. Input to be typed at the Maple prompt. Output from Maple. An important tip. MAPLE Maple is a powerful and widely used mathematical software system designed by the Computer Science Department of the University of Waterloo. It can be used for a variety of tasks, such as solving

More information

CSE143 Notes for Monday, 4/25/11

CSE143 Notes for Monday, 4/25/11 CSE143 Notes for Monday, 4/25/11 I began a new topic: recursion. We have seen how to write code using loops, which a technique called iteration. Recursion an alternative to iteration that equally powerful.

More information

PHP Personal Home Page PHP: Hypertext Preprocessor (Lecture 35-37)

PHP Personal Home Page PHP: Hypertext Preprocessor (Lecture 35-37) PHP Personal Home Page PHP: Hypertext Preprocessor (Lecture 35-37) A Server-side Scripting Programming Language An Introduction What is PHP? PHP stands for PHP: Hypertext Preprocessor. It is a server-side

More information

Chapter 2 Basic Elements of C++

Chapter 2 Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion

More information

SPARK-PL: Introduction

SPARK-PL: Introduction Alexey Solovyev Abstract All basic elements of SPARK-PL are introduced. Table of Contents 1. Introduction to SPARK-PL... 1 2. Alphabet of SPARK-PL... 3 3. Types and variables... 3 4. SPARK-PL basic commands...

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 04 Programs with IO and Loop We will now discuss the module 2,

More information

Well, Hal just told us how you build robust systems. The key idea was-- I'm sure that many of

Well, Hal just told us how you build robust systems. The key idea was-- I'm sure that many of MITOCW Lecture 3B [MUSIC PLAYING] Well, Hal just told us how you build robust systems. The key idea was-- I'm sure that many of you don't really assimilate that yet-- but the key idea is that in order

More information

The Stack, Free Store, and Global Namespace

The Stack, Free Store, and Global Namespace Pointers This tutorial is my attempt at clarifying pointers for anyone still confused about them. Pointers are notoriously hard to grasp, so I thought I'd take a shot at explaining them. The more information

More information

So on the survey, someone mentioned they wanted to work on heaps, and someone else mentioned they wanted to work on balanced binary search trees.

So on the survey, someone mentioned they wanted to work on heaps, and someone else mentioned they wanted to work on balanced binary search trees. So on the survey, someone mentioned they wanted to work on heaps, and someone else mentioned they wanted to work on balanced binary search trees. According to the 161 schedule, heaps were last week, hashing

More information

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG 1 Notice Reading Assignment Chapter 1: Introduction to Java Programming Homework 1 It is due this coming Sunday

More information

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi. Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 18 Tries Today we are going to be talking about another data

More information

6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

More information

Decisions, Decisions. Testing, testing C H A P T E R 7

Decisions, Decisions. Testing, testing C H A P T E R 7 C H A P T E R 7 In the first few chapters, we saw some of the basic building blocks of a program. We can now make a program with input, processing, and output. We can even make our input and output a little

More information

Module 1: Introduction RStudio

Module 1: Introduction RStudio Module 1: Introduction RStudio Contents Page(s) Installing R and RStudio Software for Social Network Analysis 1-2 Introduction to R Language/ Syntax 3 Welcome to RStudio 4-14 A. The 4 Panes 5 B. Calculator

More information

Lecture 12. PHP. cp476 PHP

Lecture 12. PHP. cp476 PHP Lecture 12. PHP 1. Origins of PHP 2. Overview of PHP 3. General Syntactic Characteristics 4. Primitives, Operations, and Expressions 5. Control Statements 6. Arrays 7. User-Defined Functions 8. Objects

More information

Learning Objectives. Description. Your AU Expert(s) Trent Earley Behlen Mfg. Co. Shane Wemhoff Behlen Mfg. Co.

Learning Objectives. Description. Your AU Expert(s) Trent Earley Behlen Mfg. Co. Shane Wemhoff Behlen Mfg. Co. PL17257 JavaScript and PLM: Empowering the User Trent Earley Behlen Mfg. Co. Shane Wemhoff Behlen Mfg. Co. Learning Objectives Using items and setting data in a Workspace Setting Data in Related Workspaces

More information

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Java Programming Fundamentals - Day Instructor: Jason Yoon Website: Java Programming Fundamentals - Day 1 07.09.2016 Instructor: Jason Yoon Website: http://mryoon.weebly.com Quick Advice Before We Get Started Java is not the same as javascript! Don t get them confused

More information

Fortunately, you only need to know 10% of what's in the main page to get 90% of the benefit. This page will show you that 10%.

Fortunately, you only need to know 10% of what's in the main page to get 90% of the benefit. This page will show you that 10%. NAME DESCRIPTION perlreftut - Mark's very short tutorial about references One of the most important new features in Perl 5 was the capability to manage complicated data structures like multidimensional

More information