Basic questions for php beginners

Source: Internet
Author: User
Basic questions for php beginners: I used to be a beginner in PHP. I used to be an asp.net beginner. now I have a rough understanding of PHP syntax, and I have also downloaded other code templates for reference, may I ask you two questions?
1. as shown in step 1, PHP code is mixed with HTML. can I write it separately? Html is the html code, and PHP code is the PHP code. The combination of the two types of code is messy and not conducive to maintenance.

As shown in 2.2, there are two PHP code segments in the body. so when the page is loaded, what code does it run? Or are both running? Which one does it run first? If there are two buttons on the same page to implement different functions, how can I click button 1 and execute A PHP code (such as method )? Click button 2 to execute a PHP code (such as Method B )?
I hope you can help me solve this problem.

:


:


Reply to discussion (solution)

1. can asp.net code be separated? I only know that C # uses companion files for code separation.
Php needs to introduce the template engine class for code separation

2. don't you have a programming foundation? isn't the code separated by conditional statements?
Since the code is in the condition branch, it is naturally conditional execution.

Use a framework such as thinkphp or a template such as smarty to separate php from html.
Php files are executed sequentially from top to bottom.

Search for php MVC
Views are separated from logic and data!

1. can asp.net code be separated? I only know that C # uses companion files for code separation.
Php needs to introduce the template engine class for code separation

2. don't you have a programming foundation? isn't the code separated by conditional statements?
Since the code is in the condition branch, it is naturally conditional execution.



The code has a conditional branch. if the code is written as follows:
Echo "";
?>
Echo "B ";
?>
In this case, will both A and B be output? Are all output during page loading? Can I just run the first PHP code (that is, only output A) when loading A page?

If you do not want to output data, place it in the condition or branch, or comment it out.
I doubt you have actually done asp.net?

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.