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.

When making a PHP API request, use `curl` to receive the response as an array.

When making a PHP API request, use `curl` to receive the response as an array. Language Notes PHP

This isn't particularly complex code; I previously used `file_get_contents`, but the overall performance felt suboptimal. I remember having published a similar article before – I'd forgotten about it – so I'll document it again here. This example uses the cURL library to send an HTTP request with several options configured: `CURLOPT_URL`: Sets the URL for the request; `CURLOPT_TIMEOUT`: Sets the request timeout duration (in seconds)...
👁 175
PHP uses `curl` to download a file; if the download is successful, it returns the file path; if it fails, it returns a download link.

PHP uses `curl` to download a file; if the download is successful, it returns the file path; if it fails, it returns a download link. Language Notes PHP

I've written similar functionality before, but I didn't take any notes at the time, so I eventually forgot about it. Recently, I've started writing this code again, so I'd like to document it here! PHP code: public function downloadFile($url, $path) {// Check if the file exists if (file_exists($path)) {// Check if the file size is greater than 10 KB if...
👁 182
Implement Baidu In-site Search Code Using jQuery on a Website

Implement Baidu In-site Search Code Using jQuery on a Website Language Notes PHP

First, we use the `$(document).ready()` method to ensure that the subsequent code is executed only after the document has been fully loaded. Then, we select the form element with the class name ` 'sform' ` and register a `submit` event listener. Within the handler function for the `submit` event, we first use the `e.preventDefault()` method to prevent the form's default submission behavior, thereby avoiding redirection to the Baidu search page. Then...
👁 206
Generate a random 15-character string using PHP.

Generate a random 15-character string using PHP. Language Notes PHP

The following code generates a random 15-character string: <?php function generateRandomString($length = 15) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ...';
👁 146
What are the second parameters for `json_encode`?

What are the second parameters for `json_encode`? Language Notes PHP

The second parameter of the `json_encode` function is optional and is used to specify encoding options. Here are some commonly used encoding options: `JSON_HEX_QUOT`: Escapes double quotation marks to `\u0022`. `JSON_HEX_TAG`: Escapes `<` and `>` within HTML tags to `\u003C` and `\u003E`. `JSON_HEX_AMP`: Escapes the character `...`.
👁 218
EmpireCMS "Locomotive" – No-Login PHP API Code (Automatic Categorization)

EmpireCMS "Locomotive" – No-Login PHP API Code (Automatic Categorization) Language Notes PHP

<?php /******** Password Verification ***********/ $password='123456'; //这个密码是登陆验证用的.您需要在模块里设置和这里一样的密码....注意一定需要修改. if($password!=$_GET['pw']); exit('Incorrect password'); // Security check,...
👁 359
How to implement PJAX on a website

How to implement PJAX on a website Language Notes PHP

PJAX (PushState + AJAX) is a page-load technique that enables seamless page navigation and partial content updates on websites without refreshing the entire page. Below is a brief guide on how to use PJAX to implement non-refreshing page loading on a website: Integrate the PJAX library – First, include the PJAX library on your website, such as pjax.js or the jQuery pjax plugin...
👁 197
PHP randomly generates a number within a specified range and outputs it separated by English commas.

PHP randomly generates a number within a specified range and outputs it separated by English commas. Language Notes PHP

Here is a simple PHP function used to generate random numbers within a specified range and return them as a string separated by English commas: `function generateRandomNumbers($min, $max, $count) { $numbers = array(); for ($i = 0; $i <$count; $...`
👁 181
PHP determines the day of the week based on a specified date.

PHP determines the day of the week based on a specified date. Language Notes PHP

You can use PHP's `date()` function with the parameter `' l '` to determine the day of the week for a specified date. Here is an example code that determines what day of the week the date `' 2023-07-24 '` falls on: $date = '2023-07-24'; $dayOfWeek = date('l',strtotime($date(' l'); echo $day...
👁 149
Here's a very practical article featuring pseudo-original PHP code.

Here's a very practical article featuring pseudo-original PHP code. Language Notes PHP

This code can randomly insert ASCII characters into an article, while the frontend can hide these ASCII characters – thereby ensuring that the user experience remains unaffected while simultaneously misleading Baidu's web crawler, achieving a pseudo-original content effect. This code was extracted from several novel websites and is highly practical! PHP code: function randAscii($string) {if (empty...
👁 333
1 2 3 4 5 6 22