1 00:00:00,420 --> 00:00:02,710 As we covered in the php basics course, 2 00:00:02,710 --> 00:00:06,740 a variable is a piece of code that references some data. 3 00:00:06,740 --> 00:00:09,020 There are several types of variables. 4 00:00:09,020 --> 00:00:12,340 Throughout this course, we'll be using strings, integers, 5 00:00:12,340 --> 00:00:16,810 meaning whole numbers, arrays, and touch briefly on objects. 6 00:00:16,810 --> 00:00:19,430 The first one we'll be using is a string variable. 7 00:00:19,430 --> 00:00:21,550 To change the title tag from page to page. 8 00:00:23,000 --> 00:00:25,230 Let's go back into the suggest.php file. 9 00:00:26,530 --> 00:00:30,180 Let's start by specifying the page title for the suggest page. 10 00:00:30,180 --> 00:00:35,330 Right before this line where we include the header, let's add a variable or 11 00:00:35,330 --> 00:00:35,940 page title. 12 00:00:38,640 --> 00:00:42,930 As a refresher, variables in PHP are represented by a dollar sign 13 00:00:42,930 --> 00:00:44,830 followed by the name of the variable. 14 00:00:44,830 --> 00:00:47,310 Variable names are case sensitive. 15 00:00:47,310 --> 00:00:49,860 We can make up just about any name we want for our variable. 16 00:00:50,950 --> 00:00:53,260 A valid variable name starts with a letter or 17 00:00:53,260 --> 00:00:58,190 an underscore, followed by any number of letters, numbers, or underscores. 18 00:00:58,190 --> 00:01:01,240 There's no predefined list of variables we have to choose from. 19 00:01:01,240 --> 00:01:03,700 But it's good practice to make your names descriptive so 20 00:01:03,700 --> 00:01:05,800 that your code is easier to read. 21 00:01:05,800 --> 00:01:14,670 Let's assign our variable page title, a string value of suggest a media item. 22 00:01:16,630 --> 00:01:22,340 If we assign this value to the variable in our code before we include header.php, 23 00:01:22,340 --> 00:01:25,310 then we can reference this variable in that include file. 24 00:01:26,420 --> 00:01:29,660 Open header.php. 25 00:01:29,660 --> 00:01:31,010 Here we have the page title, 26 00:01:31,010 --> 00:01:33,520 where we've told it to simply echo out the actual title. 27 00:01:36,730 --> 00:01:38,510 This is not very useful. 28 00:01:38,510 --> 00:01:42,810 Let's replace the string Personal Media Library, with our variable, page title. 29 00:01:48,749 --> 00:01:51,040 Be sure to type the variable name exactly. 30 00:01:51,040 --> 00:01:53,330 Again, upper and lowercase characters do matter. 31 00:01:54,580 --> 00:01:58,430 Save both files, and let's take a look at suggest in our browser. 32 00:02:00,820 --> 00:02:05,660 When we refresh the page, notice how the title on the tab has changed. 33 00:02:05,660 --> 00:02:08,490 Let's take a closer look at what's happening in our code. 34 00:02:08,490 --> 00:02:13,360 When suggest.php first loads, our code creates a variable named $pageTitle and 35 00:02:13,360 --> 00:02:16,500 assigns it a value of "Suggest a Media Item". 36 00:02:16,500 --> 00:02:18,780 Then our code includes header.php. 37 00:02:18,780 --> 00:02:21,360 Which echos out the value in that page title variable. 38 00:02:22,380 --> 00:02:25,358 Let's add the same variable with different values to our other pages. 39 00:02:25,358 --> 00:02:29,640 Open catalog.php. 40 00:02:29,640 --> 00:02:33,650 And let's add this variable right before I include 41 00:02:35,690 --> 00:02:40,820 page title equals Full catalog. 42 00:02:43,920 --> 00:02:46,710 Now lets go into index.php and do the same thing. 43 00:02:51,380 --> 00:02:54,470 A new variable, page, title. 44 00:02:56,030 --> 00:03:01,490 And we'll assign this the value of Personal Media Library. 45 00:03:03,920 --> 00:03:05,030 Now let's go back to our browser. 46 00:03:06,180 --> 00:03:09,740 As we click through the menu, we can see our title changing as we go. 47 00:03:13,120 --> 00:03:17,120 By assigning a value to a variable before the header file gets included, 48 00:03:17,120 --> 00:03:20,570 we can use the same PHP code for all the pages but 49 00:03:20,570 --> 00:03:23,440 still give them unique values for their title tags.