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.

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
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
Using ChatGPT with the official API to generate articles – PHP Tutorial

Using ChatGPT with the official API to generate articles – PHP Tutorial Language Notes PHP

I heard this tool is really popular and awesome – many webmasters have started using it to generate articles or build websites. So, I wrote a simple PHP script that integrates with the official API; it's quite straightforward: just use Composer to install the required package and then simply make calls to the API. I tested it out – with just one API key, you can generate 900 articles, and the quality is quite good. For the API call tutorial, head over to this link to find a PHP package; after looking through several options, I chose this one: ope...
👁 163
PHP implode() function

PHP implode() function Language Notes PHP

The function combines array elements into a single string: <code>PHP arr = array('Hello', 'World!', 'I', 'love', 'Shanghai!'); echo implode(", arr);</code>
👁 175
PHP serialize() function

PHP serialize() function Language Notes PHP

The `serialize()` function serializes an object or an array and returns a string. After serializing an object, you can easily pass it to other parts of your code that require it, without any changes to its type or structure. To convert a serialized string back into a PHP value, you can use the ` unserialize()` function. PHP version requirement: PHP 4, PH...
👁 148
php import sql file into database

php import sql file into database Language Notes PHP PHP collection PHP and mysql

Using PHP to import an SQL file into a database is commonly employed during source code installation; this code encapsulates a class sourced from the internet: <?php /** * Created by PhpStorm. * User: Administrator * Date: 2018/10/13 * Time: 10:25 */ class ImportData{/...
👁 217
PHP generates random numbers with specified number of digits

PHP generates random numbers with specified number of digits Language Notes PHP

How can I generate a random number with 70 to 80 digits? To solve this problem, I wrote a function: "`php function rand_num($num = 1){ &nbsp;&nbsp;&nbsp; $num = (int) $num; $rand ="; //... "`
👁 186
Create a folder in php and set the access permission to 7777

Create a folder in php and set the access permission to 7777 Language Notes PHP

define('CACHE_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cacheFile'); if(!file_exists(CACHE_ROOT)){ mkdir(CACHE_ROOT,0777); chmod(CACHE_ROOT,07…
👁 144
PHP generates fixed number based on title

PHP generates fixed number based on title Language Notes PHP

substr(str_replace(array(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;,&quot;e&quot;,&quot;f&quot;,&quot;g&quot;,&quot;h&quot;,&quot;i&quot;…
👁 134
php sql read and write operation database

php sql read and write operation database Language Notes PHP PHP collection PHP and mysql

I am about to learn object-oriented, so some codes need to be deleted. Here is a record. This string of code is mainly used for writing operations in the empire database, etc.
👁 123
1 14 15 16 17 18 22