Home >Backend Development >PHP Tutorial >An interesting technical article PHP introduction_PHP tutorial

An interesting technical article PHP introduction_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:34:07874browse

As an intermediate PHPer novice, I like to browse various PHP forums when I am bored. I have seen many PHP beginners asking a lot of the same questions. And I also encountered them when I was learning PHP. In order to Let PHP beginners avoid some detours. So I suddenly felt nervous and decided to write this article. It is only for reference for PHP beginners. If there are any mistakes, please point them out. I am very grateful.
PHP is actually a very simple and easy to learn method. Language. If you want to be proficient in PHP, it will take at least three years and at least one year is enough. But why are we still novices after three years?
I don’t know where to start. To learn PHP, we have to learn databases and learn architecture. Learning object-oriented, learning front-end, learning Linux, learning protocols and even art directly leads to the fact that PHP is now the most tiring type of programmer.
The most tiring is nothing. PHP is often considered inferior. Programmers earn the lowest salary but have to master almost all knowledge about the web. This is really unfair.
The good news is that we are gradually seeing changes in China. More and more companies in China are switching from Java or C# Wait until I switch to PHP. So all PHPers must have their own dreams. You will all be awesome. Please believe in me.
I’m going too far. Back to the point I want to make. The following questions include what I encountered Question. Maybe what I said is not necessarily correct or you may not necessarily agree with me. I am very willing to accept your opinion. In short, we just want to make all PHPers rise:-)
1. Encoding issues
This is not just PHP. As long as it is a program, you will encounter it. At least I and the people around me have encountered it. And in terms of Web, coding problems are often very difficult to solve and very difficult to debug. Sometimes there are inexplicable problems with the program, and it is difficult to think that there is a coding problem, etc.
These problems always bother us. So I suggest that PHP beginners must unify the coding. And it is strongly recommended to unify to UTF- 8. It is not recommended to use GBK or GB2312 for Chinese because this encoding is not recognized when transmitting in AJAX.
If you want to unify the encoding, you must pay attention to any place where the encoding may appear.

1) Header encoding
Personally suggest that you should add the following sentence in your PHP (except for special headers)

Copy code The code is as follows:

header("Content-type: text/html;charset=utf-8");

This can avoid some problems. For example, we can I saw that some websites will get an alert and then jump after submitting, but they have not set the encoding. If its encoding is inconsistent with the browser's default encoding, garbled characters will appear.
You are just HTML. Be sure to remember to Put the meta encoding tag in front of the title tag. If you don’t understand, just remember to put the encoding information in the first line of the head tag. The final effect is like this
Copy code The code is as follows:



...

2) File encoding
When we save the file, the encoding must be consistent. If we follow the above, we should choose UTF-8.
General editors have encoding information for this file .If you find that it is not UTF-8, please change it immediately.
For example, we opened a template file in Dreamweaver and found that GB2312 (Simplified Chinese) is displayed in the lower right corner. Do not make any changes at this time. CTRL+J immediately and select Change the encoding to UTF-8 mode and save.
The encoding of the file is not necessarily a PHP file. You must also ensure that your JavaScript files and css files are both UTF-8 encoded.
There is another important point . It’s BOM.. This stuff is not very popular with PHP. So we have to choose UTF-8 BOM-free format when saving. If the editor you use is UE, then please pay attention to this.
3) Database encoding
I don’t want to say more about this. There are too many articles on the Internet. If you are MySQL, remember to SET NAMES = 'utf8' after each connection. And there is no horizontal line in the middle of utf8 Line.
2. Problems with MVC
In theory, programmers should be perfectionists. They not only think about writing programs that run well, but also elegantly.
But having said that, will our code be elegant after making the program according to MVC? The answer is of course no.
Learning architecture is a process of understanding. When you truly realize the benefits of this architecture. Only then will you understand its true meaning. Don’t be blind.
Sometimes we will make such a plan. Use this month to learn MVC. Well, I think you should do it this way. You learn to set goals for yourself
But we may not really understand MVC in a month.. But at least we will learn its basics according to its model. In other words, maybe we have not learned the Sunflower Book. But we should be able to use the evil sword technique. .
3. Object-oriented issues
Regarding PHP object-oriented issues, I have always been entangled. Some people don’t think PHP object-oriented is a good thing. Some people don’t even think that it is a good thing. I think object-oriented is a good thing, such as Linus.
We don’t have to worry about whether this thing is good or not. At least we should know that from the birth of object-oriented to the present, after so many years of evolution, it has been applied to various projects and even languages. .We have reason to believe that existence has its own reason.
Practice is the only criterion for testing truth. Over the years, object-oriented development has become better and better. It seems that it is necessary for us to learn.
With some architectures The knowledge is similar. Object-oriented is not that easy to learn. Object-oriented is a concept. But when it comes to a certain language, its meaning will also undergo some subtle changes.
PHP's object-oriented is very flexible. In addition, Its unique magic method will create a special situation of object-oriented. Maybe this is different from the object-oriented you usually see in Java.
Putting the methods you need into a class does not necessarily mean it is object-oriented. When you truly realize that object-oriented brings speed and convenience to your coding, you will have a deeper understanding of object-oriented.
As the saying goes, haste makes waste. Don’t be impatient. How many times do you think about it? Tian Nei’s understanding of the theory of relativity is pure nonsense.
4. Problems with algorithms
It seems that PHP is always far away from algorithms. Most of PHP’s algorithms are implemented based on arrays. We also know that the characteristics of PHP's arrays are destined to cause the efficiency to plummet when the array becomes very large.
In fact, PHP is just for making websites. We don't need to give it any high hat. Especially on the Web. In the actual situation of the front-end served by PHP, there will be very few places involving algorithms.
PHP algorithm interview questions are nothing more than operations on arrays or strings. Use your brain and add a manual. That's basically it. No problem.
Then you may ask. I want to learn PHP. Do I also need to learn algorithms?
I think you need to learn. And more importantly, you need to learn data structures. This course is like an internal skill. . It will affect your coding in a subtle way.
At this time, we will cooperate with our previous evil-proof sword technique. Congratulations, you have learned the Sunflower Book!
5. Framework issues
PHP has the most frameworks among various languages. Whether to use a framework or not. Which framework to choose has become a controversial topic.
My suggestion is to learn at least one framework. This can deepen your understanding of PHP. Understand. When we learn a framework, we don’t mean to learn how to use this framework or how to do projects.
We have to look at its source code and see how it is implemented. At this time, you can choose to develop a small framework yourself. We don’t ask for how well we do it. We don’t ask for how many projects others can use.
We are just here to learn.
6. JavaScript issues
It can be said that I have seen so many languages. The most amazing one is JavaScript. Java always claims that everything is an object. In fact, I think JavaScript is everything is an object.
Is JavaScript easy to learn? Easy to learn! In fact, in daily life on the Web When used, general JavaScript operations are DOM operations.
Is JavaScript difficult to learn? Difficult to learn! If we are bound by the object-oriented thinking of other languages, it will be difficult to understand the object-oriented nature of JavaScript. And the concepts in JavaScript are also very complex.
Prototype arguments call apply callee caller Closures and other concepts overwhelm us. Coupled with the weird JavaScript code style and its difficult to debug characteristics, it directly caused us rookies to avoid it.
Once I forwarded a piece of code that implements document.ready. I have to admire how weird it is.
Personally, I think looking at the source code of some JavaScript frameworks is the best way to learn. When I was writing my PHP framework, I used Unified Entrance + self-defined URL rules. So when you use the form with the normal attribute of get, you will not be able to get the parameters.
At this time, I thought of the formSerialize method in jQuery.form. I extracted it and did some Modify it and you can use it.
7. CSS issues
What I want to talk about is separating CSS from JavaScript. I think learning CSS is more unique.
Actually I would say that CSS is the simplest thing. We just know some basic CSS properties. Writing pages is definitely not a problem.
The main feature of CSS is that you have to do it. It is better to actually write it than to read N CSS books. A page.
Another characteristic of CSS is to try more. Maybe this attribute cannot achieve your effect. Then you can change it. This is also the stupidest and most effective way:-)
Of course this is just for elementary CSS. Requirements. After knowing these, we still need to be compatible with browsers. In fact, this is not difficult. It is just a trial of opening one attribute and one attribute in several browsers at the same time.
You can also memorize some hacks, such as IE6 knows it_ IE knows it *etc. If you feel that writing CSS in this way is not standard enough, then put the hack in a different css file. For example, for ie6, it is called ie6.css
and then use the following code on the page.
Copy code The code is as follows:



Of course the more advanced thing is the user experience and design. I don’t understand this so I won’t talk about it @_@ I hope experts can add more.
8. Linux issues
Personal It is strongly recommended that everyone install a Linux system on their computer. If you feel it is too much trouble, you can choose the wubi method to install Ubuntu. For lazy people, this is the simplest and most effective method.
When you are bored, you can download a copy of the PHP source code Try compiling it yourself. Be careful not to apt-get, because often the server version is either rhel or centos. There is no such command there.
And what apt-get gets is often not the latest version. And you can’t customize it yourself.
Linux will always have such inexplicable problems. For example, if the environment is slightly different, the compilation will not pass or the service will not start.
Don’t worry at this time. Look at the error message and log. Google and try to solve it yourself.
Don’t think it’s over after compilation. Try different configurations. Modify the source code and try compiling again.
For example, if we download a copy of the nginx source code, and then modify some places such as the header, you can compile one of your own. HTTP Web Server.
Of course, you can also call it BWS or GWS :-)
I also have a question. Does Linux need to memorize commands? This is understandable. Memorizing some common commands can improve the speed. This point I need to reflect. Often you need to look at the parameters for some commonly used commands.
The other problem is Shell. Shell is actually not difficult. But the syntax is ugly in my opinion@_@. You can learn most of it by looking at the wiki Yes.. The main thing is to contact. We can see a phenomenon. Some companies also list this as a required condition when recruiting senior PHPers.
In fact, there is a lot of Linux information on the Internet. Most of the information you encounter Problems are encountered by everyone else, so be good at using Google. And be familiar with English.
9. Language problem
This problem is too much of a war of words. In the end, no one can defeat the other. We don’t have to participate in these boring things. These are what young people have to do.
No matter how awesome you are, do you have Linus? He has been complaining about C++ for so many years. How is C++?
So we don’t have to worry about these. Just do what you do.
Since you chose PHP, don’t hesitate.
Maybe PHP is not enough when we are doing the project. Then we can use Java or C is used as a middleware. This is not a bad idea.
It is true that a language can be used to its fullest potential.
10. Attitude issues
The attitude must be modest and prudent . This is the virtue that a programmer should have. Never be self-aggrandizing.
The more you learn, the more you will find that you are deficient.
When you become awesome, you can say some arrogant things. But none of us are awesome now. At least if you read this article I wrote, you probably aren’t very awesome yet. I said this article is for beginners:-)
11. Women’s problems
Uh... let’s solve this by ourselves @_@

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322484.htmlTechArticleAs an intermediate PHPer novice... When I get bored, I like to wander around in various PHP forums. I saw a lot of PHP Beginners have asked many of the same questions. And I have encountered them when I was learning PHP. In order to let...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn