Home >Backend Development >PHP Tutorial >Collection of PHP tips, every PHPer will show their skills_PHP tutorial

Collection of PHP tips, every PHPer will show their skills_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:58:57858browse

This post is mainly for all PHPers to summarize some of their experience and skills in development or learning, mainly to tell everyone better ways to solve certain things.
Let me talk about a few first:

1. If you use echo to output a simple statement, similar to:

Copy the code The code is as follows:
echo "Hello World!";
?>
Then you can be lazy and write it like this:


2, str_replace() can use arrays for replacement, such as:
Copy code The 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;
?>

Don’t hide all your experience, ^_^!
How many tricks are considered tricks?
I remember that I posted this cache variable function before. The cache directory needs to have read and write permissions. There is also a function for scheduled refresh. I won’t write it out yet. Otherwise, it will appear that this technique is too big. In fact, compare it with the refresh mode of dz. Like
Copy code The 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, "");
f close($ fp);
return true;
return false;
}

http://www.bkjia.com/PHPjc/317497.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317497.htmlTechArticleThis post is mainly for all PHPers to summarize some of their experience and skills in development or learning. The main thing is to Let me tell you a better way to solve a certain problem. Let me tell you a few first: 1. Fake...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn