Judging teacher PHP Devil special Training Note (10)

Source: Internet
Author: User
Tags php form vars

  In order to prevent the code to confuse us, we look at the video of the separation method 1, a new folder called Code (this means Code) 2, and then create a new folder called Page (this is the Page)

How do you write the code? Here to remember the formula 1, index.php is always "the main manager." Always load code and page 2, code inside the file can only write PHP code 3, page inside the file, in principle to write html, but can embed some PHP code. Please see the video operation for Details.

  For some reason, we stipulate that any file that writes a variable must be var.php as a file suffix such as code1.var.php. Then we often need to write a "code final compiler" (idea Extension) we go back to our God program, the design requirements are as follows 1, the receiving parameter "compile" 2, the parameter implementation of the code folder inside the xxx.var.php form of the file read out, for Processing.

1, we write a compile method in the God_frame

    functionCompile () {//read the duplicate variables in code to get rid of them .       $_files=Scandir($thisProject_folder. ' /code '); foreach($_files  as $_file){           if(Preg_match("/\w+\.var\.php$/i",$_file)){               require($this->project_folder. ' /code/'.$_file); unset($_file); }       }        unset($_files);//destroy this invalid Variable//var_export (get_defined_vars ());        $result= ' <?php '.Php_eol.‘ Ectract ('.Var_export(Get_defined_vars(), 1). '); '; file_put_contents($this->project_folder. " /vars.php ",$result);//}

This method is called in Godinit:

    Static function compile () {        $get _config = loadconfig ();         $GF new god_frame ($get _config-prj_name);         $gf  -compile ();    }

So we can see that in our custom folder, a vars.php file is generated

Knowledge Points:

The Scandir function, which lists the files and directories in the specified path (returns an Array)

Var_export ();

Regular matching function (simple Use) preg_match (regular expression, to match the content); True if match to return

Get_defined_vars (); Returns an array of all defined Variables.

Unset: destroys the specified variable;

Copyright notice: Note-taker Fugitive Pawns Love freedom, advocating sharing. But this note stems from www.jtthink.com (programmer in the awkward way) judging teacher's "php Devil training First stage." This study note pawn in the blog Park debut, if need to reprint please respect the teacher labor, retain judging teacher attribution and course source Address.

Previous lesson: judging teacher PHP Devil Special Training Note (9)-evolution

Judging teacher PHP Devil special Training Note (10)

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.