Home >Backend Development >PHP Tutorial >Programming experience sharing: PHP skills accumulated in daily life_PHP tutorial

Programming experience sharing: PHP skills accumulated in daily life_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:56:39818browse

Reprinted by Agni Website Building Academy I would like to share with you the PHP skills I have accumulated in daily life. Some of them may be very basic, but when everyone has a brain short-circuit, there is no harm in taking it out and looking through it... ...
If there are any mistakes, I would like to point them out, or share my accumulated skills

PHP code
PHP代码
public function GetIP(){
if (getenv("HTTP_CLIENT_IP")&& strcasecmp(getenv("HTTP_CLIENT_IP"),"unknown")) {
$ip = getenv("HTTP_CLIENT_IP");
}
elseif (getenv("HTTP_X_FORWARDED_FOR")&& strcasecmp(getenv("HTTP_X_FORWARDED_FOR"),"unknown")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
}
elseif (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) {
$ip = getenv("REMOTE_ADDR");
}
elseif (isset($_SERVER['REMOTE_ADDR'])&$_SERVER['REMOTE_ADDR']&strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) {
$ip = $_SERVER['REMOTE_ADDR'];
}
else
$ip = "unknown";
return($ip);
}
public function GetIP(){ if (getenv("HTTP_CLIENT_IP")&& strcasecmp(getenv("HTTP_CLIENT_IP" ),"unknown")) { $ip = getenv("HTTP_CLIENT_IP"); } elseif (getenv("HTTP_X_FORWARDED_FOR")&& strcasecmp(getenv("HTTP_X_FORWARDED_FOR"),"unknown") ) { $ip = getenv("HTTP_X_FORWARDED_FOR"); } elseif (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) { $ ip = getenv("REMOTE_ADDR"); } elseif (isset($_SERVER['REMOTE_ADDR'])&$_SERVER['REMOTE_ADDR']&strcasecmp($_SERVER['REMOTE_ADDR'], "unknown") ) { $ip = $_SERVER['REMOTE_ADDR']; } else $ip = "unknown"; return($ip); }


2. Jump

3. /(^[0-9]| ^[1-9][d]{1,3})($|[.][d][1-9]$|[.][1-9]$)/; A price matching regular

4. js obtains random numbers from 1 to 10 document.write(Math.floor(Math.random()*10+1)); //Random numbers from 1 to 10

5. mysql Get random records SELECT * FROM lzyblog_shop_category ORDER BY RAND() limit 5

6. js: onpropertychange triggers the event when the object properties change

7. Filter out the SQL of year and month
SELECT regdate FROM `analyse_system` GROUP BY year( regdate ) + month( regdate ) ORDER BY `regdate` DESC
or SELECT regdate FROM `analyse_system` GROUP BY left(regdate,7) ORDER BY `regdate` DESC

8. strrev string flip

9. basename(__FILE__); get the file name

10. implode(spacer symbol, array) explode(spacer symbol, string )

11. Underlined CSS

asdfasdf< /a>

12. Perl efficiency issues

1) When processing text files, you usually read them line by line. In such a loop, never use external shell commands. For example, if If you want to write the analysis content to other files, you should honestly use perl's own way of writing file handles instead of using shell commands such as "echo $_ >;file". The latter is 10,000 times slower than the former. times.
2) When matching regular expressions, if the match contains the "&" character, remember to add an "" escape in front, otherwise perl will copy the matching content for future reference, which will cause the program to It is extremely slow;
3) When matching regular expressions, try not to use the i option (case-sensitive). Please reduce the case-insensitive area as much as possible, for example /ID=something&/i, if you only match ID If it is not case-sensitive, then it should be written like this: /[Ii][Dd]=something&/, the latter is more than 100 times faster than the former;
4) When matching regular expressions, if the matching item is fixed , then please use the o option, which means that the regular expression is only compiled once. For example, /jsp/io is much better than /jsp/i.
5) while loops are more efficient than for/foreach loops,
6) Use more parentheses and less $&, $`, $'
7) It is recommended to modify redundant lines with s/m symbol, it is not recommended to use $*

13. Linux modification time
date -s 07/5/10 &&
date -s 09:28:00 &&
#clock -w

14. checkdate uses UNIX timestamp to verify the correctness of the time

15. Creation of cvs
Environment settings: specify the path of the CVS library CVSROOT

tcsh
setenv CVSROOT /path/to/cvsroot (specify the CVS path)
bash
CVSROOT=/path/to/cvsroot (specify the CVS path); export CVSROOT

Initialization: Initialization of the CVS version library.
cvs init

Import library
$ cd wdir (directory of the project)
$ cvs import -m "Imported sources" yoyodyne/rdir (expected directory name under CVSROOT) yoyo ( Author) start
import
$ cd ..
$ cvs checkout yoyodyne/rdir(project name) # Explanation below

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364169.htmlTechArticleThe Agni Website Building Academy reprints the PHP skills accumulated in daily life and shares them with everyone. Some of them may be very basic, but everyone can When there is a short circuit in the brain, there is no harm in taking it out and looking through it...such as...