Common Learning notes for PHPMVC framework view

Source: Internet
Author: User
Tags php foreach php template
This article introduces the PHPMVC framework view learning notes for future reference. let's talk about view, view... before you understand it, you may think that the template engine is amazing. after you understand it, you will think that it is so simple... for the template engine... this article introduces the learning notes of the php mvc framework view for future reference. let's talk about view, view... before you understand it, you may think that the template engine is amazing. after you understand it, you will think that it is so simple...

For the template engine, the general principle is to replace the language of the template engine with an executable language, and then output the variables... because PHP itself is a good template engine, it is very convenient and easy to use the native template engine...

The code of the index.html instance is as follows:

        <?php echo $title ?>            
        
     
   
  • The above html page uses the native php template engine. when you include this page, the server will process the PHP code in html.

    You may ask, can I customize the template language? The answer is yes, of course. As I mentioned above, the template engine language only needs to be replaced with the standard PHP language...

    The code for index_2.html is as follows:

          <?php echo $title ?>         
           
        
      
     

    Looking at this page, what is the difference between index.html and index.html? that's right. in the loop, we are not using the standard php language, but defining several template languages according to our preferences. one is This is to determine whether the xxx variable exists and is not empty. Is the xx2 variable of cyclic iteration Is the output xx variable, how to replace it with the standard language? This can be replaced with a regular expression, because string replacement cannot meet our needs.

    The instance code is as follows:

    $pattern = array(    '/
     
      /i',    '/
      
       /',    '/
       
        /'    );       $replacement = array(    '
        ', '
        
         ');    $content = str_replace($search, '
         ', $content);
        
       
      
     

    The above regular expression can help us convert the label we just defined into the standard p hp language... this is the case after the conversion. see the figure.

    Can I output the converted data? The answer is no, because when you get the content of the html file, php has already explained it. at that time, you haven't replaced it with the standard php language, so what you output now, the php code is not executed... however, we can use the php eval function to forcibly execute the code.

    The instance code is as follows:

    $content = eval(' ?>'.$content);

    Note: Yes?>. $ Content or not, php regards the html as the execution of php code, so that an error occurs... refresh, OK, and you can execute it ~~~


    Address:

    Reprinted at will, but please attach the article address :-)

    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.