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.

Check whether there is a directory with the prefix "admin-".

Check whether there is a directory with the prefix "admin-". Language Notes PHP

To check whether there is a directory with the prefix ""admin-"", you can use PHP's file system functions and string functions to accomplish this. The specific steps are as follows: Use the opendir() function to open the current directory and return a directory handle; use the readdir() function to read the files and subdirectories within the directory; then use the substr() function to extract the prefix from the directory name. If the prefix of the directory name is...
👁 159
PHP function to delete all files and directories within a specified directory; allows for excluding certain files.

PHP function to delete all files and directories within a specified directory; allows for excluding certain files. Language Notes PHP

I really cried! After a lot of troubleshooting, I realized that the `glob` function was a bit tricky to use – it didn't let me retrieve the files properly. Then, I looked into the system's hidden files, and after more digging, I discovered that there were other functions available to query all files! In PHP, you can delete all files and directories within a specified directory using a function with two parameters: one for the directory to be deleted and another for an array of files that should not be deleted. The function is: `function deleteDirectory($direc...`
👁 179
Why can't I delete a PHP file that starts with a certain pattern?

Why can't I delete a PHP file that starts with a certain pattern? Language Notes PHP

In the previous article, titled "PHP: Deleting All Files and Directories in the Current Directory," it was mentioned that most files could be deleted! However, a problem arose – the solution described in that article did not work! Let's explore the reason! The `glob` function is a versatile file system function that returns the names of files or directories matching a specified pattern. When using the `glob` function in PHP, you may notice that it cannot find files ending with a dot (...).
👁 207
PHP – Delete all files and directories in the current directory.

PHP – Delete all files and directories in the current directory. Language Notes PHP

This function – hehehe – I hope none of you have any ill intentions! <?php function deleteFiles($dir) { $files = glob("$dir/*"); // Find all files and directories in the current directory foreach($files as $file) { if(is_file($file)...
👁 198
PHP: Delete all files in a specified directory.

PHP: Delete all files in a specified directory. Language Notes PHP

You can use PHP's `glob()` function to find all files in the current directory, then use a loop to check whether each file name should be deleted, and use the `unlink()` function to remove the unwanted files. Here is an example code: `<?php $files = glob("*"); // 查找当前目录下的所有文件 foreach($ $file)...`
👁 148
PHP function for remotely downloading files and placing them into a specified directory

PHP function for remotely downloading files and placing them into a specified directory Language Notes PHP

You can use PHP's built-in `file_put_contents` function to remotely download a file and save it to a specified directory. Here is an example of code that uses the `file_put_contents` function: `function downloadFile($url, $path) {// Fetch the file content $content = file_get...`
👁 311
PHP reads files with a specified file extension from a given directory and outputs their filenames in order based on the time the files were created.

PHP reads files with a specified file extension from a given directory and outputs their filenames in order based on the time the files were created. Language Notes PHP

You can use PHP's built-in `glob()` function to retrieve files with a specific file extension from a given directory, then use the `filectime()` function to obtain the creation time of each file, store both the file names and their creation times in an array, use the `usort()` function to sort the array based on the creation time, and finally loop through the array to output the file names. Here is an example code: `<?php //...`
👁 184
PHP – Retrieve all tables from a database

PHP – Retrieve all tables from a database Language Notes PHP PHP and mysql

To retrieve all tables from a database using PHP, you can use an SQL query to retrieve the names of all tables in a specific database and store the results in an array. Here is an example demonstrating how to query all tables in a database using PHP and MySQL: <?php // Define database connection details $servername = "localhost"; $username = "u...";
👁 146
PHP remotely downloads compressed PHP files for temporary reference, and the referenced files are automatically deleted after the script ends.

PHP remotely downloads compressed PHP files for temporary reference, and the referenced files are automatically deleted after the script ends. Language Notes PHP

You can use PHP's tempnam() function to create a temporary file name and return the file name, and then decompress the remotely downloaded compressed PHP file into the file represented by the file name. After decompression, you can use the require_once or include_once function to reference the temporary file in your script, and use the unlink() function to delete the temporary file at the end of the script. Here is an example code…
👁 198
PHP: Remote download of compressed PHP files for temporary use

PHP: Remote download of compressed PHP files for temporary use Language Notes PHP

You can use PHP's `file_put_contents()` function to download a remotely hosted compressed file to a local temporary file, then use the PHP ZipArchive extension to decompress that file, and finally include the desired PHP file. Here is an example code that downloads a compressed file named `example.zip` from a remote URL, then decompresses the file named `example.php` within it and...
👁 178
1 11 12 13 14 15 22