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.

PHP foreach jumps out of this/current loop and terminates the loop method

PHP foreach jumps out of this/current loop and terminates the loop method Language Notes PHP

`continue`: Exit the current iteration; `break`: Terminate the loop; `exit`: Ends the execution of the program; `return`: Ends a block of code; $arr = array('le', 'yang', 'jun', 'lecode', 'gagade');...
👁 201
PHP gets Baidu drop-down words

PHP gets Baidu drop-down words Language Notes PHP

Sometimes, when performing SEO tasks, you may want to use a script to automatically modify page titles; in such cases, you can utilize Baidu's dropdown keyword database for automatic matching and modification. Below is a PHP snippet for retrieving Baidu's dropdown keyword data: // Retrieve Baidu dropdown information $title = urlencode($data['title']); $api = "https://www.baidu.com/sugrec?pr...";
👁 498
php split a string into its constituent characters

php split a string into its constituent characters Language Notes PHP

Question: How to split a string into its constituent characters in PHP? For example, hello -> [h, e, l, l, o] There are three methods: This is the string that needs to be split: $str = 'Hello sample'; The length of the string: $len = mb_strlen($str, 'utf8'); // 7 The first way: $arr = str_…
👁 182
php The day of the month, php determines the day of the week today is this month

php The day of the month, php determines the day of the week today is this month Language Notes PHP

PHP offers a powerful built-in system function called `date()`. By cleverly utilizing this function, you can display any desired date or time. For example, suppose you need to determine what day of the week today is within the current month; we won't discuss whether such a requirement is appropriate or meaningful here – instead, let's look at how to implement this functionality using PHP. This functionality primarily relies on the `w` and `j` parameters of the `date()` function.
👁 251
PHP implements several ways to write what day of the week today is

PHP implements several ways to write what day of the week today is Language Notes PHP

// First method: $da = date('w'); if ($da == '1') {echo 'Today is Monday';} else if ($da == '2') {echo 'Today is Tuesday';}...
👁 160
PHP timestamp and date conversion

PHP timestamp and date conversion Language Notes PHP

Get the current date and time as a timestamp: `echo time();`; Get the current date and time: `echo date('Y/m/d H:i:s');`; Convert a date to a timestamp: `echo strtotime(date('Y/m/d'));`; Convert a timestamp to a date: `echo date('Y-m-d', time());`
👁 148
How does PHP operate sqlite database?

How does PHP operate sqlite database? Language Notes PHP PHP collection PHP and mysql

The PHP code below demonstrates how to connect to an existing database. If the database does not yet exist, it will be created; finally, a database object will be returned. <?php class MyDB extends SQLite3 {function __construct() {$this->open('test.db'...
👁 176
A simple method to count the number of Chinese characters in PHP

A simple method to count the number of Chinese characters in PHP Language Notes PHP

This article demonstrates a simple PHP method for counting the number of Chinese characters. It is shared here for your reference; the details are as follows: Previously, at my previous company, which was engaged in foreign trade and primarily used English content, the `strlen()` function was used to count the length of strings – and this function had never caused any issues. However, when counting Chinese characters, this function began to fail. I am now conducting a test to document this issue: `<?php echo strlen("Hello ABC");...`
👁 171
php division rounding

php division rounding Language Notes PHP

When using the "/" operator for division, if the division is not exact, a floating-point number will be returned. What should I do if I only want to obtain the integer part? 1. `round` — Rounds a floating-point number. `float round(float $val [, int $precision]);` Returns the value of `val` rounded to the specified precision `precision` (...
👁 160
PHP replaces string only once

PHP replaces string only once Language Notes PHP

This is a method I found online – quite useful. It is designed for when the string A appears multiple times within string B, and you need to replace the first occurrence of string A in string B with another string; for example, this technique can be used to add links to keywords within article content. $needle=&gt;字符串A,$replace=> – The new string to replace string A with; $haystack=...
👁 190
1 15 16 17 18 19 22