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.

Use PHP to batch-import millions of TXT files into a database.

Use PHP to batch-import millions of TXT files into a database. Language Notes PHP

Currently, the MySQL database is an excellent choice for storing data; therefore, the corresponding code is: <?php // Call the function // moveFilesByExtension('~/Recycle Bin', '~/Sentence Collection', '.txt'); die(); // Database connection information $servername = "localhost"; $username...
👁 182
Move tens of millions of files with specified extensions using PHP.

Move tens of millions of files with specified extensions using PHP. Language Notes PHP

Got it! You want to write a function that takes three parameters – the source folder path, the target folder path, and the file extension – and moves files with that specific extension from the source folder to the target folder. Here's an example of the code: `function moveFilesByExtension($sourceDir, $targetDir, $fileExtension...)`
👁 186
PHP converts web pages into PDF files.

PHP converts web pages into PDF files. Language Notes PHP

1. Install TechnickCom/TCPDF. 2. Code: `<?php // Include the TCPDF class file: require_once('../vendor/autoload.php'); require('../../action/class/common.php'); // Use TCPDF\TCPDF; $f...`
👁 161
PHP + HTML + jQuery + Bootstrap – Functional page for querying and modifying a database

PHP + HTML + jQuery + Bootstrap – Functional page for querying and modifying a database Language Notes PHP mySql JavaScript Bootstrap

The screenshot is as follows: `index.html` `<!DOCTYPE html>` `<html lang="en">` `<head>` `<meta charset="UTF-8"` `<meta name="viewport" content="width=device...`
👁 259
Is there a fast way in PHP to retrieve the first.txt file from a specified folder, with high performance requirements?

Is there a fast way in PHP to retrieve the first.txt file from a specified folder, with high performance requirements? Language Notes PHP

Does not perform a full folder scan – extremely fast, at the millisecond level! You can use PHP's built-in `DirectoryIterator` to quickly retrieve the first `.txt` file within a specified folder. The specific implementation is as follows: $dir =' /path/to/dir'; // Specify the path to the target folder $iterator = new DirectoryIterator($dir);
👁 164
PHP: Deletes files with a specified suffix that are smaller than 300 KB, as well as empty files, from a specified directory.

PHP: Deletes files with a specified suffix that are smaller than 300 KB, as well as empty files, from a specified directory. Language Notes PHP

The size can be customized, and the file path can also be specified. <?php $directory = "./Music score/up"; // 替换为你想要操作的目录路径 // 递归删除文件和目录 function deleteFiles($path) {if (is_dir(pathfiles =...
👁 171
PHP query to retrieve specified files from a given directory.

PHP query to retrieve specified files from a given directory. Language Notes PHP

To search for specific files within a given directory, including all its nested subdirectories, you can use a recursive function to achieve this. Below is an example of PHP code that recursively searches for files in a specified directory: "`php function searchFiles($dir, $filename) {// Traverse the directory $files = scandir($dir); foreach ($files as $file) {// Check each file..." `
👁 323
php convert lyrics of lrc file to str subtitles

php convert lyrics of lrc file to str subtitles Language Notes PHP

This function is a PHP script designed to convert a lyrics file into an SRT subtitle file. The specific implementation process is as follows: remove any unnecessary blank lines using the regular expression `preg_replace('/^\s*$/m', ", $lrc);`, then split the lyrics text into individual lines using ` explode('\n', $lrc);`, and finally loop through each line of lyrics content using the `preg_match()` function.
👁 327
Remove the content between two specified characters in PHP without using regular expressions.

Remove the content between two specified characters in PHP without using regular expressions. Language Notes PHP

This is a PHP function designed to remove the content within specified parentheses from a string. It accepts three parameters: `$text`: the string to be processed; `$leftBracket`: the character representing the left boundary of the parentheses; `$rightBracket`: the character representing the right boundary of the parentheses. The logic of the function is as follows: first, the `strpos()` function is used to locate the first occurrence of the `$leftBracket` character within the `$text` string...
👁 140
PHP returns the URL of the current webpage; you can determine whether it is HTTP or HTTPS on your own.

PHP returns the URL of the current webpage; you can determine whether it is HTTP or HTTPS on your own. Language Notes PHP

This is a PHP function used to retrieve the URL of the current request. It constructs the URL based on the protocol, host, and path of the current request and then returns that URL. The code logic within this function is as follows: First, it determines whether the current request is using the HTTPS protocol by checking whether the value of `$_SERVER['HTTPS']` is equal to ` 'on' `. If so, the protocol is set to ` 'https' `; otherwise, it is set to ` 'http' `....
👁 134
1 2 3 4 5 22