


Classes combined with smarty specially written for novices Page 1/3_PHP Tutorial
A class specially written for novices to be used in conjunction with smarty. We sincerely invite everyone to provide valuable feedback
This is a class written for novices (and for myself) to be used in conjunction with smarty. It is unfinished Yes, the purpose of releasing it now is not to let novices use it immediately, so I haven’t written the annotations in very detail
I hope you experts can give me your opinions and I will try my best to improve it.
First of all, let me state that the purpose of writing this is to train myself. Although I know that there are many similar classes now, I still decided to write one.
So please be gentle when browsing.
I have also packaged and uploaded the files and put them below. Please download them and give your comments. If you have any questions, please ask me directly
Currently, this class includes the following functions (use example, assuming $m = new Machine_m())
[Database]
Currently supports MYSQL and ACCESS databases
Configuration refers to the config.php file
Use: $m->send_query (SQL statement) //
$m->select_query (SQL statement, whether to return resources, the default is false, which returns a two-dimensional array )
[Error handling]
Divided into system errors and user errors
System error:
$this->sys_err( 'Configuration error, please check the config configuration file', 'die ');
The first parameter will record the error information to /lib/error/system.err. The second parameter is the processing method (keep or die). If you need to modify the browser prompt, you can also set it. The third parameter, which defaults to "Sorry, a system error occurred on this site, please try again later."
User error:
$m->user_err( 'Registration system is closed', 'die' , $_SERVER['HTTP_REFERER'] );
The first parameter is the prompt displayed on the browser, the second parameter is the processing method (keep or die), the third parameter is the jump page, if you need to record If there is an error message, you can also set the fourth parameter, which will record the error message
to /lib/error/user.err. If it is not set, it will not be saved by default.
The error prompt on the browser side calls the err_page.htm template file under /lib/error/ by default. You can also set your own error template file and then load it with $m->err_page=.
[Static generation]
Automatically generate a static page with just one line, and you can set the static page expiration time when jumping
(It is still not completely static, and it is more complicated at present. There is no integration. If you want to achieve complete static, you can combine my create_html function and text operation series functions to achieve it)
Usage:
$m->create_html (template file, static output path, output file name);
Jump:
$m->goto_html();
The output file name defaults to the file name of the current php file. The purpose of providing this parameter is to use static paging when it is necessary. You can use this parameter setting
[Two-dimensional array sorting (recommended)]
to sort the two-dimensional array like: "First ascending order by field a, then descending order by field b"
Usage:
Set an array like this: $x = array( array('name'=>'machine_马', 'age'=>23),array('name'=>'tom ',age=>28),... )
We now need to sort this array in ascending order by name, and then in descending order by age
The usage is m_sort($x,'name',SORT_ASC, 'age',SORT_DESC)
[Dynamic loading]
For infrequently used functions, I use the loading method. I personally think this can save resources
For example, if we want to use the m_sort function This function is not loaded by default
You need to load it like this: $m->load_func('m_sort')
Then you can use the m_sort function
[Paging]
Here I don’t know if I did it well or not. I first wrote a class and then a function to adjust it. The purpose is to make it more convenient to use
Usage method: m_page (number of data items, current page number, each page How many rows, how many jump links to display)
The function returns an array: array(
'rows' => How many rows to display on each page,
'prve' => The page number of the previous page ,//The so-called large page is a jump like the previous 7 pages and the next 7 pages
'next' => The page number of the next large page,
'pages' => How many pages are there in total,
'start' => Number of starting records of SQL query,
'count' => How many records are there,
'links' => Link page number, //If there are 13 pages in total, link The number is 7, and it is currently on the second largest page, then output array(8,9,10,11,12,13)
'current_page' => current page number
);
[Verification Form]
Write the form that needs to be verified into the function class in advance. When judging, you only need to pass in $_POST.
Usage method: You should be able to understand this by looking at the function. This function needs to be modified according to your own needs
[Prevent cross-site attacks]
This function is also written in a function
[Chinese interception function]
It was not written by me, I just modified it
[Upload file]
m_up_file($_FILES, upload path, file type, size limit)
The upload path can be set like this, 1: Write the folder path directly, 2:array('gif'=>'file/gif','jpg'=>'file=>jpg'), so that the gif file is automatically placed in the file/gif folder, jpg Put the file into the file/jpg folder
File type: Writing method 1:'jpg', Writing method 2:array('jpg','jpeg','gif')
Return array( 'arr' => Array of uploaded files, 'err_msg' => Error message during upload, 'num' => Number of successful uploads)
[Text operation (recommended)]
Suppose there is such a character String $str="Hellophpchina";
We can modify it like this $new_str=m_txt_replace('content','machine_马',$str);
Now the value of $new_str is "Hellomachine_马"
Several others Functions such as: m_txt_add, m_txt_delete, m_txt_get are similar, you can refer to them yourself.
Note: This is how to modify the static page after generating it.
You can refer to 6to23 and think about why he posted so many replies in one post and it is so fast
Answer: Because its replies are not entered into the database but written directly into the static file, and then use a method similar to mine above to modify. You can look at his source code and look for

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor