Hongmu Notes
Home Language Notes

Language Notes

PHP: Remote download of a ZIP file, extract it, and overwrite it into a specified directory.

PHP: Remote download of a ZIP file, extract it, and overwrite it into a specified directory. Language Notes PHP

This feature is commonly used for updating programs – I suppose you know how to use it! It's incredibly practical! PHP implementation code: // URL of the remote ZIP file $zipUrl =' https://example.com/install.zip '; // Target file path $targetPath =' /path/to/install'; // Download the z...
👁 400
PHP modifies the configuration in the config file

PHP modifies the configuration in the config file Language Notes PHP PHP collection PHP and mysql

In PHP development websites, configuration files such as config.php generally require users to submit data for saving through the background. At this time, PHP is needed to operate this file! At this time, we need to use PHP to modify this PHP file. For example, the code in my config.php is like this: <?php if(!defined('InEmpireCMS'))…
👁 299
PHP regular match all pictures in the article

PHP regular match all pictures in the article Language Notes PHP PHP collection

You can use PHP's regular expression function preg_match_all() to match all image links in the article. The regular expression can be matched according to the format of the image link. Here is an example: function getImagesFromContent($content) { $pattern = '/<img.*?src=[\'…
👁 409
PHP function to replace image links in an article with randomly selected links

PHP function to replace image links in an article with randomly selected links Language Notes PHP

A PHP function for matching image links within an article using regular expressions and replacing them with specified image links: `function replaceImageLinks($content, $newImageLink) {// Match the src attribute within <img> tags $pattern = '/<img.*?src="(.*?)".*?>';`
👁 191
Use PHP to batch rename files in a folder, starting from number 1 while keeping the file extensions unchanged.

Use PHP to batch rename files in a folder, starting from number 1 while keeping the file extensions unchanged. Language Notes PHP

Function: 🔒 Hidden content: Viewable after logging in – function renameFiles($dir) { // 获取目录下所有文件 $files = glob($dir './'); if (empty($files)) {return;} $i = 1; foreach ($files as $file)...
👁 163
Selects a random file from a specified folder and returns its file name.

Selects a random file from a specified folder and returns its file name. Language Notes PHP

A PHP function to randomly retrieve a file name from a specified directory: 🔒 Hidden content: Viewable after logging in. `function getRandomFileName($dir) {// /*... */; if (empty($files)) {return null;}`
👁 285
jquery click to jump to the top of the web page

jquery click to jump to the top of the web page Language Notes JavaScript

You can use jQuery to jump to the top of the web page after clicking on an element. The following is a simple implementation method: $(document).ready(function() { // Listen to the click event of the element $('#my-element').click(function() { // Scroll to the top $('html, body').an…
👁 205
PHP batch replaces file names in specified folders

PHP batch replaces file names in specified folders Language Notes PHP

The following is a PHP function that can batch rename file names in a specified folder: 🔒 Hidden content: You can view the function after logging in batchRenameFiles($dir, $search, $replace) { $files = scandir($dir); // Get all files in the directory foreach ($files…
👁 235
How can I write a jQuery condition that stops code execution if the value is empty?

How can I write a jQuery condition that stops code execution if the value is empty? Language Notes JavaScript

You can use the conditional statement if to make a judgment. If the value of a variable or expression is empty, use the return keyword to terminate the execution of the function. For example: function myFunction() { var myVar = $('#myInput').val(); if (!myVar) { // If the value of myVar is empty, use ! …
👁 156
What does .on do in jquery? What's the use?

What does .on do in jquery? What's the use? Language Notes JavaScript

.on() is the event binding method provided by jQuery, which is used to bind one or more event handling functions on the specified DOM element. The syntax structure is as follows: $(selector).on(event, childSelector, data, handler); where event is one or more event types, such as "click", "mouseov...
👁 146
1 19 20 21 22 23 33