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.

PclZip serves as a replacement for ZipArchive, resolving PHP error issues!

PclZip serves as a replacement for ZipArchive, resolving PHP error issues! Language Notes PHP

PclZip is a PHP-based ZIP archive library that allows you to easily create, read, and extract ZIP files. Unlike the ZipArchive class, PclZip does not require the PHP Zip extension. After spending an entire afternoon experimenting, I ultimately decided to give up on ZipArchive – I really had to give up on it! The original requirement was: "Download a ZIP file remotely using PHP, extract it, and overwrite it into a specified directory; if the specified directory does not exist, then..."
👁 175
PHP script for remotely downloading a ZIP file, extracting it, and overwriting files into a specified directory; if the specified directory does not exist, it will be created; if the directory already exists, it will be emptied. The extracted ZIP file contains files with Chinese filenames.

PHP script for remotely downloading a ZIP file, extracting it, and overwriting files into a specified directory; if the specified directory does not exist, it will be created; if the directory already exists, it will be emptied. The extracted ZIP file contains files with Chinese filenames. Language Notes PHP

This PHP script allows for the remote download and extraction of a ZIP file, overwriting files in a specified directory; if the specified directory does not exist, it will be created; if the directory already exists, it will be emptied. The extracted ZIP file contains files with Chinese filenames. I previously wrote an article titled "PHP Remote Download and Extraction of a ZIP File, Overwriting Files in a Specified Directory" – you may refer to it for guidance. However, after implementing this code, I encountered an issue: specifically, an error is thrown if the target directory does not exist! During extraction...
👁 247
Check whether the directory exists; if it does, delete all files within the directory; if it does not, create the directory.

Check whether the directory exists; if it does, delete all files within the directory; if it does not, create the directory. Language Notes PHP

You can use PHP's built-in functions `file_exists()` and `is_dir()` to check whether a directory exists. If the directory exists, you can use the `glob()` function to retrieve all files within it and then use the `unlink()` function to delete them. If the directory does not exist, you can use the `mkdir()` function to create it. Here is an example code that implements the above functionality: $d...
👁 151
PHP executes multiple sql statements at once

PHP executes multiple sql statements at once Language Notes PHP PHP and mysql

In PHP, you can execute multiple SQL statements at once through the mysqli_multi_query() function. The following is a sample code: <?php // Define MySQL database connection parameters $host = "localhost"; $user = "root"; $password = "password";…
👁 477
PHP executes the specified sql statement

PHP executes the specified sql statement Language Notes PHP PHP and mysql

This function is mainly used to execute sql statements and return success or failure! 🔒 Hidden content: viewable after logging in/** * Execute the specified SQL statement * * @param string $sql SQL statement to be executed * @param string $db_host database host name * @param string $db_user database…
👁 175
PHP batch deletes data tables with specified prefix

PHP batch deletes data tables with specified prefix Language Notes PHP PHP and mysql

In PHP, you can use the SHOW TABLES command of the MySQL database to obtain the names of all data tables in the current database, and then use the DROP TABLE command to delete data tables with a specified prefix in batches. The following is a simple PHP function for batch deleting data tables with specified prefixes: function deleteTables($prefix) { /…
👁 189
PHP checks whether a specified string exists.

PHP checks whether a specified string exists. Language Notes PHP

In PHP, you can use the built-in string function strpos() to check whether a specified string exists within another string. Below is an example of using the strpos() function to determine whether a specified string is present: 🔒 Hidden content: View after commenting. $myString = "This is a sample string"; $findString = "s...";
👁 171
After PHP uploads the sql file, clear the mysql database and then import the sql file

After PHP uploads the sql file, clear the mysql database and then import the sql file Language Notes PHP PHP and mysql

Very practical operation! PHP code: 🔒 Hidden content: Viewable after logging in<?php // Connect to MySQL database $host = "localhost"; // MySQL server address $username = "your_username"; // MySQL username $password = "your_pa…
👁 227
PHP modify data table prefix

PHP modify data table prefix Language Notes PHP PHP and mysql

Manual modification of one or two tables in the database is fine! But I have more than 260 tables with data, and it’s exhausting to do it manually! At this time, you need to use PHP to make batch modifications! To replace the table prefix of a MySQL database, you need to perform the following steps: Connect to the MySQL database. Query all table names in the database. Iterate through each table, replacing its name with the new prefix. Execute an ALTER TABLE statement for each table to modify the table name...
👁 171
PHP redirects to the /e/admin directory under the current domain name.

PHP redirects to the /e/admin directory under the current domain name. Language Notes PHP

You can use the `header()` function in PHP to redirect the user to the `/e/admin` directory under the current domain name. You can retrieve the current domain name using `$_SERVER['HTTP_HOST']`, concatenate it with `/e/admin`, and then use the `header()` function to perform the redirection. Here is an example code snippet: `<?php // Get the current domain name...`
👁 209
1 12 13 14 15 16 22