Hongmu Notes
Home Language Notes PHP

PHP

PHP (Hypertext Preprocessor) is a server-side scripting language particularly suited for web development and can be embedded within HTML. Its syntax is derived from the C language, incorporating features from languages such as Java and Perl to develop its own distinctive grammar; it has also been continuously refined and enhanced based on the strengths of these languages—for example, leveraging Java's object-oriented programming capabilities.

Convert text-based lyrics into HTML-format lyrics.

Convert text-based lyrics into HTML-format lyrics. Language Notes PHP

Lyrics to be converted: [01:04.81] Hello [02:57.54][00:42.86] True affection is as vast as the grasslands [03:04.81][00:50.07] Layers of wind and rain cannot separate us [05:04.81] Conversion result: <p data-time="01:04.81">Hello</p> <p da...
👁 163
Why does this code produce an extra '1' when executed? <?=require('./common/aside.php')?>

Why does this code produce an extra '1' when executed? <?=require('./common/aside.php')?> Language Notes PHP

Why does this code produce an extra '1' when executed? <?= require('common/aside.php');?> In PHP, the `require` and `include` statements are used to include the content of other PHP files into the current file. These statements allow code to be reused across multiple files, thereby improving code reusability and maintainability. In the code snippet above...
👁 186
After PHP collects data, process the function of collecting the data

After PHP collects data, process the function of collecting the data Language Notes PHP

Function: function xxfseo_body($body){ $body = preg_replace('~<(?!img)(\w+)\s+[^>]*>~i','<$1>', $body); $body = preg_replace("/<(iframe.*?)…
👁 3365
Back up some PHP code from Yiyun.

Back up some PHP code from Yiyun. Language Notes PHP

I conducted some testing and scraped songs from Yiyun – approximately over 20,000 artists and 10 million songs in total. Naturally, I have deleted all this data; the primary purpose was to write and experiment with some code, so I've backed up the code here. Scraping songs based on artist ID: 🔒 Hidden content: Members can view <?php $shuju_file = "shuju.txt"; $shuju = @json_decode...
👁 146
PHP reads the content of a text file line by line, outputs 100 lines at a time, and supports paginated output.

PHP reads the content of a text file line by line, outputs 100 lines at a time, and supports paginated output. Language Notes PHP

You have a TXT file containing one million titles, with one title per line. Each time you access the file, you are passed a `pageid`; when `pageid` is 1, the first to 100 titles in the file are output; when `pageid` is 2, the 101st to 200th titles are output; and so on. The PHP code is also very simple: 🔒 Hidden content: Members can view <?php // Open the title file $ha...
👁 173
A PHP function that adds or subtracts a specified amount of time from a timestamp and returns the result in a specified format.

A PHP function that adds or subtracts a specified amount of time from a timestamp and returns the result in a specified format. Language Notes PHP PHP and mysql

Here is a PHP function that adds or subtracts a specified amount of time from a timestamp and then outputs the resulting time in a specified format: <?php /** * Adds or subtracts a specified amount of time from a timestamp and outputs the resulting time in a specified format * * @param string $time-Date-time string in the format 'Y-m-d H:i:s' * @param int $seconds-The amount of time to add...
👁 148
PHP connects to the database and determines whether the SQL statement is executed successfully

PHP connects to the database and determines whether the SQL statement is executed successfully Language Notes PHP

I must be getting increasingly lazy – just leave this code here, and you can simply copy it next time you need to use it! <?php // Set database connection parameters $servername = "localhost"; // Server name $username = "your_username"; // Username $password = "your_password"; // Password...
👁 108
If you want to use Class B within Class A in PHP, how can you do it?

If you want to use Class B within Class A in PHP, how can you do it? Language Notes PHP

If you want to use one class within another PHP class, you can leverage PHP's class instantiation mechanism to create a new class instance and use it. Suppose you have two classes, A and B, and class A needs to use class B; you can instantiate class B within class A. For example: class A { public function doSomething() { $b = new B(); $b->do... }}
👁 151
Remove duplicates from a PHP string after splitting it

Remove duplicates from a PHP string after splitting it Language Notes PHP

Super simple code: // Split the keywords into an array, remove duplicates, then combine them into a single string $uniqueKeywords = implode(',', array_unique(explode(',', $keywords))); This is commonly used for keyword deduplication.
👁 108
PHP: Delete files with a specified file extension from a given directory.

PHP: Delete files with a specified file extension from a given directory. Language Notes PHP

You can use PHP's `glob` function to match file names within a specified directory and then use the `unlink` function to delete them. The specific steps are as follows: Use the `glob` function to match the file names in the specified directory and store them in an array; the code is as follows: `$files = glob(' /path/to/dir/*.txt');` where `/path/to/dir` refers to the directory you wish to operate on...
👁 239
1 3 4 5 6 7 22