PHP Learning Summary (i)

Source: Internet
Author: User
Tags php template urlencode

"PHP Object-oriented

    1. If the current file has a namespace (namespace) when the PDO class is instantiated, the output will cause an error if the PDO class does not exist in the directory, so a backslash must be added before the PDO: \pdo
    2. instantiating a class can also be stored without variables, such as: New PDO ()
    3. preg_match ($pattern, $string); Returns the number of matches, parameter one is the regular expression, the second is the match content, this function matches only once, matches all please with Preg_match_all
    4. preg_ Replace ('/\{\$ ([\w]+) \}/', ' B ', ' {$dd}f imitation {$dd}4s65f '); Replace the regular match to the content and return, parameter one is the expression, the second is the replacement content, the third is the original text
    5. json_encode (); function Chinese garbled (u265/similar case ) and part of the symbol are converted by the workaround:
foreach ($data as $key = + $value) {$data [$key] = UrlEncode ($value);}
    1. UrlEncode for each value, return to UrlDecode (Json_encode ())!
    2. Namespace (namespace) used: A file app\ctrl\model.php, whose namespace should be namespace App\ctrl;
    3. Spec: namespace per-level initial capitalization, class name capitalization, constant all caps
    4. "Namespace and use keyword
    5. Start a namespace for the class: namespace plugin;
    6. Access this class with use: Using Plugin\nos;
    7. Note: This class must be introduced (include) when using use to access the class
    8. It is recommended to use Spl_autoload_register () to automatically load non-existent classes for you


"PHP Template

1. Why should I use a template?

    • To separate PHP and HTML code, make maintainability even higher!

2. Why should I cache a template?

    • To increase loading speed, improve performance and database endurance!

3. Why do I need to compile the template into a php file?

    • The template uses some custom syntax, such as {$name}, in order to make it normal to display, you need to convert it to <?php echo $name output, the converted file compiled into a file, the next call directly!

4. How do I cache a template?

    • Put the introduced compilation file as buffer Ob_start () and then use Ob_get_contents () to save the copied content to the cache file with File_put_contents ()

PHP Learning Summary (i)

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.