PHP_Advance.pptx - PHP:HypertextPreprocess or Advance 1...

This preview shows page 1 - 9 out of 39 pages.

PHP: Hypertext Preprocess or Advance Designed by Mr. Shahid Waseem (UOSA) 1
Image of page 1

Subscribe to view the full document.

PHP 5 Date and Time Mr. Shahid Waseem (UOSA) 2 The PHP date() function formats a timestamp to a more readable date and time. Syntax date( format , timestamp ) Parameter Description format Required. Specifies the format of the timestamp timestamp Optional. Specifies a timestamp. Default is the current date and time
Image of page 2
PHP Script PHP Script Output Output Mr. Shahid Waseem (UOSA) <!DOCTYPE html> <html> <body> <?php echo "Today is " . date("Y/m/d") . "<br>"; echo "Today is " . date("Y.m.d") . "<br>"; echo "Today is " . date("Y-m-d") . "<br>"; echo "Today is " . date("l") ; ?> </body> </html> Today is 2014/12/19 Today is 2014.12.19 Today is 2014-12-19 Today is Friday 3 PHP 5 Date and Time
Image of page 3

Subscribe to view the full document.

PHP 5 Date and Time Mr. Shahid Waseem (UOSA) 4 The required format parameter of the date() function specifies how to format the date (or time). Here are some characters that are commonly used for dates: d - Represents the day of the month (01 to 31) m - Represents a month (01 to 12) Y - Represents a year (in four digits) l (lowercase 'L') - Represents the day of the week Other characters, like"/", ".", or "-" can also be inserted between the characters to add additional formatting. The example below formats today's date in three different ways:
Image of page 4
PHP Manipulating Files Mr. Shahid Waseem (UOSA) 5 PHP has several functions for creating, reading, uploading, and editing files. When we are manipulating files you must be very careful. We can do a lot of damage if you do something wrong. Common errors are: editing the wrong file, filling a hard- drive with garbage data, and deleting the content of a file by accident.
Image of page 5

Subscribe to view the full document.

PHP readfile() Function Mr. Shahid Waseem (UOSA) 6 The readfile() function reads a file and writes it to the output buffer. Assume we have a text file called "PHPText.txt", stored on the server. The PHP code to read the file and write it to the output buffer is as follows (the readfile() function returns the number of bytes read on success): <?php echo readfile("PHPText.txt"); ?>
Image of page 6
PHP Open File - fopen() Mr. Shahid Waseem (UOSA) 7 A better method to open files is with the fopen() function. This function gives you more options than the readfile() function. <?php $myfile = fopen("PHPText.txt", "r") or die("Unable to open file!"); echo fread($myfile,filesize("PHPText.txt")); fclose($myfile); ?>
Image of page 7

Subscribe to view the full document.

PHP Open File - fopen() Mr. Shahid Waseem (UOSA) 8 The first parameter of fopen() contains the name of the file to be opened and the second parameter specifies in which mode the file should be opened. The preceding example also generates a message if the fopen() function is unable to open the specified file:
Image of page 8
Mr. Shahid Waseem (UOSA) 9 Modes Description r Open a file for read only . File pointer starts at the beginning of the file w Open a file for write only . Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file a Open a file for write only . The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist x Creates a new file for write only . Returns FALSE and an error if file already exists
Image of page 9
You've reached the end of this preview.
  • Summer '17
  • mubassar

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern