Hongmu Notes
Home Language Notes

Language Notes

How to remove duplicates from a PHP array?

How to remove duplicates from a PHP array? Language Notes PHP

In PHP, you can use the `array_unique()` function to remove duplicate elements from an array. This function takes an array as a parameter and returns a new array containing only the unique elements from the original array. Here is an example: $myArray = array('apple', 'orange', 'banana', 'orange', 'gra...
👁 134
PHP checks whether a specified directory contains a directory with a given prefix; if such a directory exists, it returns the directory name; otherwise, it creates a new directory.

PHP checks whether a specified directory contains a directory with a given prefix; if such a directory exists, it returns the directory name; otherwise, it creates a new directory. Language Notes PHP

Encapsulated code: 🔒 Hidden content: Viewable after logging in. Function `checkOrCreateDirectory($dir, $prefix, $newDirName) { $directories = array_filter(glob($dir. ''/*'), 'is_dir'); foreach ($d...`
👁 192
PHP: Check whether a directory with a specified characteristic exists; if not, create it.

PHP: Check whether a directory with a specified characteristic exists; if not, create it. Language Notes PHP

Write a PHP function that checks whether a specified directory contains a subdirectory with the prefix "admin-"; if such a directory exists, return its name; otherwise, create a new directory. The first parameter should be "admin-", and the second parameter should be the name of the new directory to be created. Here is a PHP function that implements this functionality: The function first checks whether the specified directory contains any subdirectory that starts with ""admin-""; if...
👁 170
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
JavaScript close this page after three seconds

JavaScript close this page after three seconds Language Notes JavaScript

可以使用 JavaScript 中的 setTimeout() 函数来实现页面自动关闭的效果。 The following is a sample code: setTimeout(function() { window.close(); }, 3000); In this code, the setTimeout() function will call an anonymous function after 3 seconds, and the anonymous function will call...
👁 194
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 (...).
👁 208
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)...
👁 199
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
1 16 17 18 19 20 33