What are the advantages of PHP?

Source: Internet
Author: User
Tags php foreach
What are the advantages of PHP? This post was last edited by u010572351 at 21:21:33

I found that many VIEW layers in MVC mode (for example, some search pages must write php code) write php code, which is similar to the following method and I don't understand it very much, I don't know why I want to write it like this (the following code is understandable and I don't understand it ).

For example, you need to print a fruit array in a loop (you can't understand why to write it like this, the code understands, and the purpose of doing so doesn't understand ):

 
 
 : Fresh fruit


It's messy. well, why is php code everywhere and there are N php labels? Can't I finish writing it as once below?
I think it would be nice to do this (I think it should be like this, it would be better to have php anyway ):
 ";}


However, many official programs work like this, such as dede search pages, zend framework pages, and teachers. they are all the top lines, which are hard to understand. if they are for mvc separation, but it seems like there is no separation, but it feels messy .... Solving ....




The following zend framework's if statement is a messy mix:

  
 exception)): ?>    Exception information:  

Message: exception->getMessage() ?>

Stack trace:
  exception->getTraceAsString() ?>  
Request Parameters:
  escape(var_export($this->request->getParams(), true)) ?>  


Reply to discussion (solution)

This is the characteristic of php. it embeds the program into the HTML document for execution, which greatly improves the execution efficiency.

This is the characteristic of php. it embeds the program into the HTML document for execution, which greatly improves the execution efficiency.

Is there any problem with writing a whole php just like me?

In addition, the above code is used to seal the end.


It seems that there is nothing interesting in this way, and then, the php syntax in this way seems to be a bit different. it is not quite the same as the normal php, and it is not very understandable ....

This is the first way php was written.
It seems that the idea is taken from the server side include

If you want to understand anything, you just need to remember that writing efficiency is high. You also know that the framework/cms adopts this method, and you should be able to understand it.

The biggest advantage of mixed code writing is "convenience", and the disadvantage is self-evident "disorder"
Convenience and maintainability always go from left to right, depending on which side you choose

Your first method is to embed PHP in HTML.
Your second method is to embed HTML in PHP.
The two are the same. it depends on who you take as the subject.

The advantage of Embedding PHP code in HTML compared with embedding HTML code in PHP in reading and writing is the ability to use IDE to highlight and prompt HTML code, the other is that you do not need to escape special characters.

The maintenance efficiency is relatively low, or the process is separated from the interface.

The advantage of Embedding PHP code in HTML compared with embedding HTML code in PHP in reading and writing is the ability to use IDE to highlight and prompt HTML code, the other is that you do not need to escape special characters.

Somewhat agree

In mvc v, we also need to determine that each role is different.

In fact, your example has limitations. if foreach contains a-line html tag string, if php is used to embed html, it must be a large string, it is difficult to ensure that the html tag error does not occur for large string segments. if html contains php, it is easy to detect errors in html.

If you echo html in PHP, you will not be able to implement the highlighted html scheme (all using the PHP string coloring scheme) during page editing, and it is difficult to maintain the code.

In fact, there is nothing wrong with writing habits. just like HTML, there is a starting tag and an ending tag, and PHP is also the same, such as writing If you are not familiar with it, you can write it as an HTML language.
Feeling comfortable

You are discussing this profound question.

Cainiao says it's okay to look around.

Because those guys may need tools like dw to read html code.

Mixing ...........

Maybe it's afraid someone else can change the code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.