11. **Working with Cookies**:
```php
setcookie("user", "John", time() + 3600, "/");
```
This code sets a cookie named "user" with the value "John" that will expire in one hour (3600 seconds) and is accessible from the root path ("/"). Cookies are often used to store small pieces of data on the user's browser.
12. **File Handling (Read)**:
```php
$file_content = file_get_contents("filename.txt");
```
This code reads the content of a file named "filename.txt" and stores it in the `$file_content` variable. It's a straightforward way to read the contents of a file in PHP.
13. **File Handling (Write)**:
```php
$file = fopen("newfile.txt", "w");
fwrite($file, "This is some content.");
fclose($file);
```
This code demonstrates how to open a file ("newfile.txt") for writing, write the specified content into it, and then close the file. It's used for creating or overwriting files.
14. **Date and Time**:
```php
echo date("Y-m-d H:i:s");
```
This code uses the `date` function to display the current date and time in the format "YYYY-MM-DD HH:MM:SS". PHP provides powerful date and time manipulation functions.
15. **String Manipulation**:
```php
$str = "Hello, World!";
echo strlen($str); // Length of the string
```
This code initializes a string variable and then uses the `strlen` function to determine and print the length of the string. String manipulation is essential in PHP for tasks like validation and formatting.
These code snippets continue to cover various PHP functionalities, including cookies, file handling, date and time manipulation, and string operations. They can be used as building blocks for a wide range of PHP applications.
```php
setcookie("user", "John", time() + 3600, "/");
```
This code sets a cookie named "user" with the value "John" that will expire in one hour (3600 seconds) and is accessible from the root path ("/"). Cookies are often used to store small pieces of data on the user's browser.
12. **File Handling (Read)**:
```php
$file_content = file_get_contents("filename.txt");
```
This code reads the content of a file named "filename.txt" and stores it in the `$file_content` variable. It's a straightforward way to read the contents of a file in PHP.
13. **File Handling (Write)**:
```php
$file = fopen("newfile.txt", "w");
fwrite($file, "This is some content.");
fclose($file);
```
This code demonstrates how to open a file ("newfile.txt") for writing, write the specified content into it, and then close the file. It's used for creating or overwriting files.
14. **Date and Time**:
```php
echo date("Y-m-d H:i:s");
```
This code uses the `date` function to display the current date and time in the format "YYYY-MM-DD HH:MM:SS". PHP provides powerful date and time manipulation functions.
15. **String Manipulation**:
```php
$str = "Hello, World!";
echo strlen($str); // Length of the string
```
This code initializes a string variable and then uses the `strlen` function to determine and print the length of the string. String manipulation is essential in PHP for tasks like validation and formatting.
These code snippets continue to cover various PHP functionalities, including cookies, file handling, date and time manipulation, and string operations. They can be used as building blocks for a wide range of PHP applications.