Collection of PHP tips, and every PHPer has a hand to show

Source: Internet
Author: User

In this post, all PHPers summarize some of their experience and skills in development and learning, and mainly tell you a better way to solve some things.
Let me talk about the following:

1. If you use echo to output a simple statement, it is similar:
Copy codeThe Code is as follows: <? Php
Echo "Hello World! ";
?>
Then you can be lazy and write it as follows:
<? = "Hello World! ";?>

2. str_replace () can be replaced with arrays, for example:
Copy codeThe Code is as follows: <?
$ String = "Welcome To The PHPCHINA. COM, Have A Good Time .";
$ Search = array ("Welcome To The PHPCHINA. COM", "Have A Good Time ",".");
$ Replace = array ("PHP is very Good", "I Like It ","! ");
$ Newstring = str_replace ($ search, $ replace, $ string );
Echo $ string. "<br/> ";
Echo $ newstring;
?>
Do not hide all your experiences, ^_^!
What are some tips?
I remember that the function cache directory that sent this cache variable requires read and write permissions for the cache. In addition, a function used for timed refresh is not written first. Otherwise, this technique is too great. In fact, it is similar to that of dz. the refresh mode is similar
Copy codeThe Code is as follows: function getQueryCache ($ key ){
$ CacFile = "cache/". $ key. ". php ";
If (file_exists ($ cacFile )){
@ Include ($ cacFile );
Return $ cacValue;
}
Return false;
}
Function setQueryCache ($ key, & $ result ){
$ CacFile = "cache/". $ key. ". php ";
$ Fp = fopen ($ cacFile, "w ");
If (false! = $ Fp ){
Fwrite ($ fp, "<? Php \ n \ $ cacValue = ". var_export ($ result, true)." \ n?> ");
Fclose ($ fp );
Return true;
}
Return false;
}

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.